********************************************************************************
**  TITLE:      ca2019_ces_phone						                      **  
**  AUTHORS:    P. Mongrain, N. Fréchet, B. Thompson Collart, and Y. Dufresne **
**  DATA:       2019 Canadian Election Study - Phone Survey v1.0		      **
**	DATE:		February 2025	 					                          **	
**  VERSION:	Stata 17					                                  **	
********************************************************************************

* Note: The data file needs to be downloaded from its original source (see the "surveys.text" file)

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "ca2019_ces_phone", replace

* Open the dataset

use "2019 Canadian Election Study - Phone Survey v1.1.dta", clear

* Election

gen election = "ca2019"

* Type of survey

gen type = "phone"

* Type of expectation item

gen probability = 0

* Respondent ID

gen responseid = sample_id

* Survey weight

merge 1:1 election responseid using ca2019_phone_weight
drop _merge


***********************
** DISTRICT OUTCOMES **
***********************

* Note: 1 = Conservative, 2 = Liberal, 3 = NDP, 4 = BQ, 5 = Greens, 6 = People's Party, 88 = other

rename fedui constituencynumber

gen district_outcome = .

replace district_outcome = 2 if constituencynumber == 10001
replace district_outcome = 2 if constituencynumber == 10002
replace district_outcome = 2 if constituencynumber == 10003
replace district_outcome = 2 if constituencynumber == 10004
replace district_outcome = 2 if constituencynumber == 10005
replace district_outcome = 3 if constituencynumber == 10006
replace district_outcome = 2 if constituencynumber == 10007
replace district_outcome = 2 if constituencynumber == 11001
replace district_outcome = 2 if constituencynumber == 11002
replace district_outcome = 2 if constituencynumber == 11003
replace district_outcome = 2 if constituencynumber == 11004
replace district_outcome = 2 if constituencynumber == 12001
replace district_outcome = 2 if constituencynumber == 12002
replace district_outcome = 2 if constituencynumber == 12003
replace district_outcome = 2 if constituencynumber == 12004
replace district_outcome = 2 if constituencynumber == 12005
replace district_outcome = 2 if constituencynumber == 12006
replace district_outcome = 2 if constituencynumber == 12007
replace district_outcome = 2 if constituencynumber == 12008
replace district_outcome = 2 if constituencynumber == 12009
replace district_outcome = 2 if constituencynumber == 12010
replace district_outcome = 1 if constituencynumber == 12011
replace district_outcome = 2 if constituencynumber == 13001
replace district_outcome = 2 if constituencynumber == 13002
replace district_outcome = 5 if constituencynumber == 13003
replace district_outcome = 1 if constituencynumber == 13004
replace district_outcome = 2 if constituencynumber == 13005
replace district_outcome = 2 if constituencynumber == 13006
replace district_outcome = 2 if constituencynumber == 13007
replace district_outcome = 1 if constituencynumber == 13008
replace district_outcome = 2 if constituencynumber == 13009
replace district_outcome = 1 if constituencynumber == 13010
replace district_outcome = 4 if constituencynumber == 24001
replace district_outcome = 4 if constituencynumber == 24002
replace district_outcome = 2 if constituencynumber == 24003
replace district_outcome = 2 if constituencynumber == 24004
replace district_outcome = 2 if constituencynumber == 24005
replace district_outcome = 4 if constituencynumber == 24006
replace district_outcome = 1 if constituencynumber == 24007
replace district_outcome = 4 if constituencynumber == 24008
replace district_outcome = 4 if constituencynumber == 24009
replace district_outcome = 1 if constituencynumber == 24010
replace district_outcome = 4 if constituencynumber == 24011
replace district_outcome = 4 if constituencynumber == 24012
replace district_outcome = 4 if constituencynumber == 24013
replace district_outcome = 4 if constituencynumber == 24014
replace district_outcome = 2 if constituencynumber == 24015
replace district_outcome = 2 if constituencynumber == 24016
replace district_outcome = 2 if constituencynumber == 24017
replace district_outcome = 4 if constituencynumber == 24018
replace district_outcome = 1 if constituencynumber == 24019
replace district_outcome = 4 if constituencynumber == 24020
replace district_outcome = 2 if constituencynumber == 24021
replace district_outcome = 1 if constituencynumber == 24022
replace district_outcome = 2 if constituencynumber == 24023
replace district_outcome = 2 if constituencynumber == 24024
replace district_outcome = 4 if constituencynumber == 24025
replace district_outcome = 2 if constituencynumber == 24026
replace district_outcome = 2 if constituencynumber == 24027
replace district_outcome = 2 if constituencynumber == 24028
replace district_outcome = 2 if constituencynumber == 24029
replace district_outcome = 2 if constituencynumber == 24030
replace district_outcome = 4 if constituencynumber == 24031
replace district_outcome = 4 if constituencynumber == 24032
replace district_outcome = 4 if constituencynumber == 24033
replace district_outcome = 4 if constituencynumber == 24034
replace district_outcome = 4 if constituencynumber == 24035
replace district_outcome = 2 if constituencynumber == 24036
replace district_outcome = 2 if constituencynumber == 24037
replace district_outcome = 4 if constituencynumber == 24038
replace district_outcome = 2 if constituencynumber == 24039
replace district_outcome = 2 if constituencynumber == 24040
replace district_outcome = 2 if constituencynumber == 24041
replace district_outcome = 1 if constituencynumber == 24042
replace district_outcome = 4 if constituencynumber == 24043
replace district_outcome = 2 if constituencynumber == 24044
replace district_outcome = 1 if constituencynumber == 24045
replace district_outcome = 4 if constituencynumber == 24046
replace district_outcome = 1 if constituencynumber == 24047
replace district_outcome = 4 if constituencynumber == 24048
replace district_outcome = 4 if constituencynumber == 24049
replace district_outcome = 4 if constituencynumber == 24050
replace district_outcome = 1 if constituencynumber == 24051
replace district_outcome = 2 if constituencynumber == 24052
replace district_outcome = 2 if constituencynumber == 24053
replace district_outcome = 2 if constituencynumber == 24054
replace district_outcome = 2 if constituencynumber == 24055
replace district_outcome = 2 if constituencynumber == 24056
replace district_outcome = 2 if constituencynumber == 24057
replace district_outcome = 1 if constituencynumber == 24058
replace district_outcome = 2 if constituencynumber == 24059
replace district_outcome = 4 if constituencynumber == 24060
replace district_outcome = 1 if constituencynumber == 24061
replace district_outcome = 4 if constituencynumber == 24062
replace district_outcome = 4 if constituencynumber == 24063
replace district_outcome = 3 if constituencynumber == 24064
replace district_outcome = 2 if constituencynumber == 24065
replace district_outcome = 4 if constituencynumber == 24066
replace district_outcome = 4 if constituencynumber == 24067
replace district_outcome = 2 if constituencynumber == 24068
replace district_outcome = 2 if constituencynumber == 24069
replace district_outcome = 2 if constituencynumber == 24070
replace district_outcome = 4 if constituencynumber == 24071
replace district_outcome = 4 if constituencynumber == 24072
replace district_outcome = 2 if constituencynumber == 24073
replace district_outcome = 2 if constituencynumber == 24074
replace district_outcome = 4 if constituencynumber == 24075
replace district_outcome = 4 if constituencynumber == 24076
replace district_outcome = 2 if constituencynumber == 24077
replace district_outcome = 2 if constituencynumber == 24078
replace district_outcome = 2 if constituencynumber == 35001
replace district_outcome = 3 if constituencynumber == 35002
replace district_outcome = 1 if constituencynumber == 35003
replace district_outcome = 1 if constituencynumber == 35004
replace district_outcome = 1 if constituencynumber == 35005
replace district_outcome = 2 if constituencynumber == 35006
replace district_outcome = 2 if constituencynumber == 35007
replace district_outcome = 2 if constituencynumber == 35008
replace district_outcome = 2 if constituencynumber == 35009
replace district_outcome = 2 if constituencynumber == 35010
replace district_outcome = 2 if constituencynumber == 35011
replace district_outcome = 2 if constituencynumber == 35012
replace district_outcome = 1 if constituencynumber == 35013
replace district_outcome = 1 if constituencynumber == 35014
replace district_outcome = 2 if constituencynumber == 35015
replace district_outcome = 2 if constituencynumber == 35016
replace district_outcome = 1 if constituencynumber == 35017
replace district_outcome = 2 if constituencynumber == 35018
replace district_outcome = 2 if constituencynumber == 35019
replace district_outcome = 2 if constituencynumber == 35020
replace district_outcome = 2 if constituencynumber == 35021
replace district_outcome = 1 if constituencynumber == 35022
replace district_outcome = 1 if constituencynumber == 35023
replace district_outcome = 2 if constituencynumber == 35024
replace district_outcome = 1 if constituencynumber == 35025
replace district_outcome = 1 if constituencynumber == 35026
replace district_outcome = 2 if constituencynumber == 35027
replace district_outcome = 2 if constituencynumber == 35028
replace district_outcome = 2 if constituencynumber == 35029
replace district_outcome = 1 if constituencynumber == 35030
replace district_outcome = 2 if constituencynumber == 35031
replace district_outcome = 2 if constituencynumber == 35032
replace district_outcome = 1 if constituencynumber == 35033
replace district_outcome = 1 if constituencynumber == 35034
replace district_outcome = 3 if constituencynumber == 35035
replace district_outcome = 2 if constituencynumber == 35036
replace district_outcome = 3 if constituencynumber == 35037
replace district_outcome = 2 if constituencynumber == 35038
replace district_outcome = 1 if constituencynumber == 35039
replace district_outcome = 1 if constituencynumber == 35040
replace district_outcome = 2 if constituencynumber == 35041
replace district_outcome = 1 if constituencynumber == 35042
replace district_outcome = 2 if constituencynumber == 35043
replace district_outcome = 2 if constituencynumber == 35044
replace district_outcome = 2 if constituencynumber == 35045
replace district_outcome = 2 if constituencynumber == 35046
replace district_outcome = 2 if constituencynumber == 35047
replace district_outcome = 1 if constituencynumber == 35048
replace district_outcome = 1 if constituencynumber == 35049
replace district_outcome = 1 if constituencynumber == 35050
replace district_outcome = 3 if constituencynumber == 35051
replace district_outcome = 2 if constituencynumber == 35052
replace district_outcome = 2 if constituencynumber == 35053
replace district_outcome = 2 if constituencynumber == 35054
replace district_outcome = 2 if constituencynumber == 35055
replace district_outcome = 1 if constituencynumber == 35056
replace district_outcome = 2 if constituencynumber == 35057
replace district_outcome = 2 if constituencynumber == 35058
replace district_outcome = 2 if constituencynumber == 35059
replace district_outcome = 2 if constituencynumber == 35060
replace district_outcome = 2 if constituencynumber == 35061
replace district_outcome = 2 if constituencynumber == 35062
replace district_outcome = 2 if constituencynumber == 35063
replace district_outcome = 2 if constituencynumber == 35064
replace district_outcome = 2 if constituencynumber == 35065
replace district_outcome = 2 if constituencynumber == 35066
replace district_outcome = 1 if constituencynumber == 35067
replace district_outcome = 1 if constituencynumber == 35068
replace district_outcome = 2 if constituencynumber == 35069
replace district_outcome = 2 if constituencynumber == 35070
replace district_outcome = 1 if constituencynumber == 35071
replace district_outcome = 2 if constituencynumber == 35072
replace district_outcome = 2 if constituencynumber == 35073
replace district_outcome = 1 if constituencynumber == 35074
replace district_outcome = 2 if constituencynumber == 35075
replace district_outcome = 2 if constituencynumber == 35076
replace district_outcome = 2 if constituencynumber == 35077
replace district_outcome = 2 if constituencynumber == 35078
replace district_outcome = 2 if constituencynumber == 35079
replace district_outcome = 1 if constituencynumber == 35080
replace district_outcome = 2 if constituencynumber == 35081
replace district_outcome = 1 if constituencynumber == 35082
replace district_outcome = 1 if constituencynumber == 35083
replace district_outcome = 2 if constituencynumber == 35084
replace district_outcome = 2 if constituencynumber == 35085
replace district_outcome = 1 if constituencynumber == 35086
replace district_outcome = 2 if constituencynumber == 35087
replace district_outcome = 1 if constituencynumber == 35088
replace district_outcome = 2 if constituencynumber == 35089
replace district_outcome = 2 if constituencynumber == 35090
replace district_outcome = 1 if constituencynumber == 35091
replace district_outcome = 2 if constituencynumber == 35092
replace district_outcome = 2 if constituencynumber == 35093
replace district_outcome = 2 if constituencynumber == 35094
replace district_outcome = 2 if constituencynumber == 35095
replace district_outcome = 2 if constituencynumber == 35096
replace district_outcome = 2 if constituencynumber == 35097
replace district_outcome = 2 if constituencynumber == 35098
replace district_outcome = 1 if constituencynumber == 35099
replace district_outcome = 1 if constituencynumber == 35100
replace district_outcome = 2 if constituencynumber == 35101
replace district_outcome = 1 if constituencynumber == 35102
replace district_outcome = 2 if constituencynumber == 35103
replace district_outcome = 1 if constituencynumber == 35104
replace district_outcome = 2 if constituencynumber == 35105
replace district_outcome = 2 if constituencynumber == 35106
replace district_outcome = 3 if constituencynumber == 35107
replace district_outcome = 2 if constituencynumber == 35108
replace district_outcome = 2 if constituencynumber == 35109
replace district_outcome = 2 if constituencynumber == 35110
replace district_outcome = 2 if constituencynumber == 35111
replace district_outcome = 2 if constituencynumber == 35112
replace district_outcome = 1 if constituencynumber == 35113
replace district_outcome = 2 if constituencynumber == 35114
replace district_outcome = 2 if constituencynumber == 35115
replace district_outcome = 2 if constituencynumber == 35116
replace district_outcome = 3 if constituencynumber == 35117
replace district_outcome = 2 if constituencynumber == 35118
replace district_outcome = 1 if constituencynumber == 35119
replace district_outcome = 2 if constituencynumber == 35120
replace district_outcome = 2 if constituencynumber == 35121
replace district_outcome = 1 if constituencynumber == 46001
replace district_outcome = 1 if constituencynumber == 46002
replace district_outcome = 3 if constituencynumber == 46003
replace district_outcome = 1 if constituencynumber == 46004
replace district_outcome = 3 if constituencynumber == 46005
replace district_outcome = 1 if constituencynumber == 46006
replace district_outcome = 1 if constituencynumber == 46007
replace district_outcome = 1 if constituencynumber == 46008
replace district_outcome = 2 if constituencynumber == 46009
replace district_outcome = 1 if constituencynumber == 46010
replace district_outcome = 3 if constituencynumber == 46011
replace district_outcome = 2 if constituencynumber == 46012
replace district_outcome = 2 if constituencynumber == 46013
replace district_outcome = 2 if constituencynumber == 46014
replace district_outcome = 1 if constituencynumber == 47001
replace district_outcome = 1 if constituencynumber == 47002
replace district_outcome = 1 if constituencynumber == 47003
replace district_outcome = 1 if constituencynumber == 47004
replace district_outcome = 1 if constituencynumber == 47005
replace district_outcome = 1 if constituencynumber == 47006
replace district_outcome = 1 if constituencynumber == 47007
replace district_outcome = 1 if constituencynumber == 47008
replace district_outcome = 1 if constituencynumber == 47009
replace district_outcome = 1 if constituencynumber == 47010
replace district_outcome = 1 if constituencynumber == 47011
replace district_outcome = 1 if constituencynumber == 47012
replace district_outcome = 1 if constituencynumber == 47013
replace district_outcome = 1 if constituencynumber == 47014
replace district_outcome = 1 if constituencynumber == 48001
replace district_outcome = 1 if constituencynumber == 48002
replace district_outcome = 1 if constituencynumber == 48003
replace district_outcome = 1 if constituencynumber == 48004
replace district_outcome = 1 if constituencynumber == 48005
replace district_outcome = 1 if constituencynumber == 48006
replace district_outcome = 1 if constituencynumber == 48007
replace district_outcome = 1 if constituencynumber == 48008
replace district_outcome = 1 if constituencynumber == 48009
replace district_outcome = 1 if constituencynumber == 48010
replace district_outcome = 1 if constituencynumber == 48011
replace district_outcome = 1 if constituencynumber == 48012
replace district_outcome = 1 if constituencynumber == 48013
replace district_outcome = 1 if constituencynumber == 48014
replace district_outcome = 1 if constituencynumber == 48015
replace district_outcome = 1 if constituencynumber == 48016
replace district_outcome = 1 if constituencynumber == 48017
replace district_outcome = 1 if constituencynumber == 48018
replace district_outcome = 3 if constituencynumber == 48019
replace district_outcome = 1 if constituencynumber == 48020
replace district_outcome = 1 if constituencynumber == 48021
replace district_outcome = 1 if constituencynumber == 48022
replace district_outcome = 1 if constituencynumber == 48023
replace district_outcome = 1 if constituencynumber == 48024
replace district_outcome = 1 if constituencynumber == 48025
replace district_outcome = 1 if constituencynumber == 48026
replace district_outcome = 1 if constituencynumber == 48027
replace district_outcome = 1 if constituencynumber == 48028
replace district_outcome = 1 if constituencynumber == 48029
replace district_outcome = 1 if constituencynumber == 48030
replace district_outcome = 1 if constituencynumber == 48031
replace district_outcome = 1 if constituencynumber == 48032
replace district_outcome = 1 if constituencynumber == 48033
replace district_outcome = 1 if constituencynumber == 48034
replace district_outcome = 1 if constituencynumber == 59001
replace district_outcome = 2 if constituencynumber == 59002
replace district_outcome = 3 if constituencynumber == 59003
replace district_outcome = 1 if constituencynumber == 59004
replace district_outcome = 1 if constituencynumber == 59005
replace district_outcome = 1 if constituencynumber == 59006
replace district_outcome = 1 if constituencynumber == 59007
replace district_outcome = 2 if constituencynumber == 59008
replace district_outcome = 3 if constituencynumber == 59009
replace district_outcome = 3 if constituencynumber == 59010
replace district_outcome = 2 if constituencynumber == 59011
replace district_outcome = 2 if constituencynumber == 59012
replace district_outcome = 1 if constituencynumber == 59013
replace district_outcome = 1 if constituencynumber == 59014
replace district_outcome = 1 if constituencynumber == 59015
replace district_outcome = 1 if constituencynumber == 59016
replace district_outcome = 1 if constituencynumber == 59017
replace district_outcome = 5 if constituencynumber == 59018
replace district_outcome = 3 if constituencynumber == 59019
replace district_outcome = 1 if constituencynumber == 59020
replace district_outcome = 2 if constituencynumber == 59021
replace district_outcome = 1 if constituencynumber == 59022
replace district_outcome = 1 if constituencynumber == 59023
replace district_outcome = 1 if constituencynumber == 59024
replace district_outcome = 1 if constituencynumber == 59025
replace district_outcome = 3 if constituencynumber == 59026
replace district_outcome = 5 if constituencynumber == 59027
replace district_outcome = 3 if constituencynumber == 59028
replace district_outcome = 3 if constituencynumber == 59029
replace district_outcome = 1 if constituencynumber == 59030
replace district_outcome = 1 if constituencynumber == 59031
replace district_outcome = 2 if constituencynumber == 59032
replace district_outcome = 2 if constituencynumber == 59033
replace district_outcome = 2 if constituencynumber == 59034
replace district_outcome = 3 if constituencynumber == 59035
replace district_outcome = 88 if constituencynumber == 59036
replace district_outcome = 3 if constituencynumber == 59037
replace district_outcome = 3 if constituencynumber == 59038
replace district_outcome = 2 if constituencynumber == 59039
replace district_outcome = 2 if constituencynumber == 59040
replace district_outcome = 3 if constituencynumber == 59041
replace district_outcome = 2 if constituencynumber == 59042
replace district_outcome = 2 if constituencynumber == 60001
replace district_outcome = 2 if constituencynumber == 61001
replace district_outcome = 3 if constituencynumber == 62001

label define outcome 1 "Conservative Party of Canada" 2 "Liberal Party of Canada" 3 "New Democratic Party of Canada" 4 "Bloc Québécois" 5 "Green Party of Canada" 6 "People's Party of Canada'" 88 "Other"
label values district_outcome outcome

* Constituency name

gen constituencyname = ""

replace constituencyname = "Avalon" if constituencynumber == 10001
replace constituencyname = "Bonavista—Burin—Trinity" if constituencynumber == 10002
replace constituencyname = "Coast of Bays—Central—Notre Dame" if constituencynumber == 10003
replace constituencyname = "Labrador" if constituencynumber == 10004
replace constituencyname = "Long Range Mountains" if constituencynumber == 10005
replace constituencyname = "St. John's East" if constituencynumber == 10006
replace constituencyname = "St. John's South—Mount Pearl" if constituencynumber == 10007
replace constituencyname = "Cardigan" if constituencynumber == 11001
replace constituencyname = "Charlottetown" if constituencynumber == 11002
replace constituencyname = "Egmont" if constituencynumber == 11003
replace constituencyname = "Malpeque" if constituencynumber == 11004
replace constituencyname = "Cape Breton—Canso" if constituencynumber == 12001
replace constituencyname = "Central Nova" if constituencynumber == 12002
replace constituencyname = "Cumberland—Colchester" if constituencynumber == 12003
replace constituencyname = "Dartmouth—Cole Harbour" if constituencynumber == 12004
replace constituencyname = "Halifax" if constituencynumber == 12005
replace constituencyname = "Halifax West" if constituencynumber == 12006
replace constituencyname = "Kings—Hants" if constituencynumber == 12007
replace constituencyname = "Sackville—Preston—Chezzetcook" if constituencynumber == 12008
replace constituencyname = "South Shore—St. Margarets" if constituencynumber == 12009
replace constituencyname = "Sydney—Victoria" if constituencynumber == 12010
replace constituencyname = "West Nova" if constituencynumber == 12011
replace constituencyname = "Acadie—Bathurst" if constituencynumber == 13001
replace constituencyname = "Beauséjour" if constituencynumber == 13002
replace constituencyname = "Fredericton" if constituencynumber == 13003
replace constituencyname = "Fundy Royal" if constituencynumber == 13004
replace constituencyname = "Madawaska—Restigouche" if constituencynumber == 13005
replace constituencyname = "Miramichi—Grand Lake" if constituencynumber == 13006
replace constituencyname = "Moncton—Riverview—Dieppe" if constituencynumber == 13007
replace constituencyname = "New Brunswick Southwest" if constituencynumber == 13008
replace constituencyname = "Saint John—Rothesay" if constituencynumber == 13009
replace constituencyname = "Tobique—Mactaquac" if constituencynumber == 13010
replace constituencyname = "Abitibi—Baie-James—Nunavik—Eeyou" if constituencynumber == 24001
replace constituencyname = "Abitibi—Témiscamingue" if constituencynumber == 24002
replace constituencyname = "Ahuntsic-Cartierville" if constituencynumber == 24003
replace constituencyname = "Alfred-Pellan" if constituencynumber == 24004
replace constituencyname = "Argenteuil—La Petite-Nation" if constituencynumber == 24005
replace constituencyname = "Avignon—La Mitis—Matane—Matapédia" if constituencynumber == 24006
replace constituencyname = "Beauce" if constituencynumber == 24007
replace constituencyname = "Beauport—Limoilou" if constituencynumber == 24008
replace constituencyname = "Bécancour—Nicolet—Saurel" if constituencynumber == 24009
replace constituencyname = "Bellechasse—Les Etchemins—Lévis" if constituencynumber == 24010
replace constituencyname = "Beloeil—Chambly" if constituencynumber == 24011
replace constituencyname = "Berthier—Maskinongé" if constituencynumber == 24012
replace constituencyname = "Thérèse-De Blainville" if constituencynumber == 24013
replace constituencyname = "Pierre-Boucher—Les Patriotes—Verchères" if constituencynumber == 24014
replace constituencyname = "Bourassa" if constituencynumber == 24015
replace constituencyname = "Brome—Missisquoi" if constituencynumber == 24016
replace constituencyname = "Brossard—Saint-Lambert" if constituencynumber == 24017
replace constituencyname = "Rimouski-Neigette—Témiscouata—Les Basques" if constituencynumber == 24018
replace constituencyname = "Charlesbourg—Haute-Saint-Charles" if constituencynumber == 24019
replace constituencyname = "Beauport—Côte-de-Beaupré—Île d'Orléans—Charlevoix" if constituencynumber == 24020
replace constituencyname = "Châteauguay—Lacolle" if constituencynumber == 24021
replace constituencyname = "Chicoutimi—Le Fjord" if constituencynumber == 24022
replace constituencyname = "Compton—Stanstead" if constituencynumber == 24023
replace constituencyname = "Dorval—Lachine—LaSalle" if constituencynumber == 24024
replace constituencyname = "Drummond" if constituencynumber == 24025
replace constituencyname = "Gaspésie—Les Îles-de-la-Madeleine" if constituencynumber == 24026
replace constituencyname = "Gatineau" if constituencynumber == 24027
replace constituencyname = "Hochelaga" if constituencynumber == 24028
replace constituencyname = "Honoré-Mercier" if constituencynumber == 24029
replace constituencyname = "Hull—Aylmer" if constituencynumber == 24030
replace constituencyname = "Joliette" if constituencynumber == 24031
replace constituencyname = "Jonquière" if constituencynumber == 24032
replace constituencyname = "La Pointe-de-l'Île" if constituencynumber == 24033
replace constituencyname = "La Prairie" if constituencynumber == 24034
replace constituencyname = "Lac-Saint-Jean" if constituencynumber == 24035
replace constituencyname = "Lac-Saint-Louis" if constituencynumber == 24036
replace constituencyname = "LaSalle—Émard—Verdun" if constituencynumber == 24037
replace constituencyname = "Laurentides—Labelle" if constituencynumber == 24038
replace constituencyname = "Laurier—Sainte-Marie" if constituencynumber == 24039
replace constituencyname = "Laval—Les Îles" if constituencynumber == 24040
replace constituencyname = "Longueuil—Charles-LeMoyne" if constituencynumber == 24041
replace constituencyname = "Lévis—Lotbinière" if constituencynumber == 24042
replace constituencyname = "Longueuil—Saint-Hubert" if constituencynumber == 24043
replace constituencyname = "Louis-Hébert" if constituencynumber == 24044
replace constituencyname = "Louis-Saint-Laurent" if constituencynumber == 24045
replace constituencyname = "Manicouagan" if constituencynumber == 24046
replace constituencyname = "Mégantic—L'Érable" if constituencynumber == 24047
replace constituencyname = "Mirabel" if constituencynumber == 24048
replace constituencyname = "Montarville" if constituencynumber == 24049
replace constituencyname = "Montcalm" if constituencynumber == 24050
replace constituencyname = "Montmagny—L'Islet—Kamouraska—Rivière-du-Loup" if constituencynumber == 24051
replace constituencyname = "Mount Royal" if constituencynumber == 24052
replace constituencyname = "Notre-Dame-de-Grâce—Westmount" if constituencynumber == 24053
replace constituencyname = "Outremont" if constituencynumber == 24054
replace constituencyname = "Papineau" if constituencynumber == 24055
replace constituencyname = "Pierrefonds—Dollard" if constituencynumber == 24056
replace constituencyname = "Pontiac" if constituencynumber == 24057
replace constituencyname = "Portneuf—Jacques-Cartier" if constituencynumber == 24058
replace constituencyname = "Québec" if constituencynumber == 24059
replace constituencyname = "Repentigny" if constituencynumber == 24060
replace constituencyname = "Richmond—Arthabaska" if constituencynumber == 24061
replace constituencyname = "Rivière-des-Mille-Îles" if constituencynumber == 24062
replace constituencyname = "Rivière-du-Nord" if constituencynumber == 24063
replace constituencyname = "Rosemont—La Petite-Patrie" if constituencynumber == 24064
replace constituencyname = "Marc-Aurèle-Fortin" if constituencynumber == 24065
replace constituencyname = "Saint-Hyacinthe—Bagot" if constituencynumber == 24066
replace constituencyname = "Saint-Jean" if constituencynumber == 24067
replace constituencyname = "Saint-Laurent" if constituencynumber == 24068
replace constituencyname = "Saint-Léonard—Saint-Michel" if constituencynumber == 24069
replace constituencyname = "Saint-Maurice—Champlain" if constituencynumber == 24070
replace constituencyname = "Salaberry—Suroît" if constituencynumber == 24071
replace constituencyname = "Shefford" if constituencynumber == 24072
replace constituencyname = "Sherbrooke" if constituencynumber == 24073
replace constituencyname = "Vaudreuil—Soulanges" if constituencynumber == 24074
replace constituencyname = "Terrebonne" if constituencynumber == 24075
replace constituencyname = "Trois-Rivières" if constituencynumber == 24076
replace constituencyname = "Ville-Marie—Le Sud-Ouest—Île-des-Soeurs" if constituencynumber == 24077
replace constituencyname = "Vimy" if constituencynumber == 24078
replace constituencyname = "Ajax" if constituencynumber == 35001
replace constituencyname = "Algoma—Manitoulin—Kapuskasing" if constituencynumber == 35002
replace constituencyname = "Aurora—Oak Ridges—Richmond Hill" if constituencynumber == 35003
replace constituencyname = "Barrie—Innisfil" if constituencynumber == 35004
replace constituencyname = "Barrie—Springwater—Oro-Medonte" if constituencynumber == 35005
replace constituencyname = "Bay of Quinte" if constituencynumber == 35006
replace constituencyname = "Beaches—East York" if constituencynumber == 35007
replace constituencyname = "Brampton Centre" if constituencynumber == 35008
replace constituencyname = "Brampton East" if constituencynumber == 35009
replace constituencyname = "Brampton North" if constituencynumber == 35010
replace constituencyname = "Brampton South" if constituencynumber == 35011
replace constituencyname = "Brampton West" if constituencynumber == 35012
replace constituencyname = "Brantford—Brant" if constituencynumber == 35013
replace constituencyname = "Bruce—Grey—Owen Sound" if constituencynumber == 35014
replace constituencyname = "Burlington" if constituencynumber == 35015
replace constituencyname = "Cambridge" if constituencynumber == 35016
replace constituencyname = "Chatham-Kent—Leamington" if constituencynumber == 35017
replace constituencyname = "Davenport" if constituencynumber == 35018
replace constituencyname = "Don Valley East" if constituencynumber == 35019
replace constituencyname = "Don Valley North" if constituencynumber == 35020
replace constituencyname = "Don Valley West" if constituencynumber == 35021
replace constituencyname = "Dufferin—Caledon" if constituencynumber == 35022
replace constituencyname = "Durham" if constituencynumber == 35023
replace constituencyname = "Eglinton—Lawrence" if constituencynumber == 35024
replace constituencyname = "Elgin—Middlesex—London" if constituencynumber == 35025
replace constituencyname = "Essex" if constituencynumber == 35026
replace constituencyname = "Etobicoke Centre" if constituencynumber == 35027
replace constituencyname = "Etobicoke—Lakeshore" if constituencynumber == 35028
replace constituencyname = "Etobicoke North" if constituencynumber == 35029
replace constituencyname = "Flamborough—Glanbrook" if constituencynumber == 35030
replace constituencyname = "Glengarry—Prescott—Russell" if constituencynumber == 35031
replace constituencyname = "Guelph" if constituencynumber == 35032
replace constituencyname = "Haldimand—Norfolk" if constituencynumber == 35033
replace constituencyname = "Haliburton—Kawartha Lakes—Brock" if constituencynumber == 35034
replace constituencyname = "Hamilton Centre" if constituencynumber == 35035
replace constituencyname = "Hamilton East—Stoney Creek" if constituencynumber == 35036
replace constituencyname = "Hamilton Mountain" if constituencynumber == 35037
replace constituencyname = "Hamilton West—Ancaster—Dundas" if constituencynumber == 35038
replace constituencyname = "Hastings—Lennox and Addington" if constituencynumber == 35039
replace constituencyname = "Huron—Bruce" if constituencynumber == 35040
replace constituencyname = "Kanata—Carleton" if constituencynumber == 35041
replace constituencyname = "Kenora" if constituencynumber == 35042
replace constituencyname = "King—Vaughan" if constituencynumber == 35043
replace constituencyname = "Kingston and the Islands" if constituencynumber == 35044
replace constituencyname = "Kitchener Centre" if constituencynumber == 35045
replace constituencyname = "Kitchener—Conestoga" if constituencynumber == 35046
replace constituencyname = "Kitchener South—Hespeler" if constituencynumber == 35047
replace constituencyname = "Lambton—Kent—Middlesex" if constituencynumber == 35048
replace constituencyname = "Lanark—Frontenac—Kingston" if constituencynumber == 35049
replace constituencyname = "Leeds—Grenville—Thousand Islands and Rideau Lakes" if constituencynumber == 35050
replace constituencyname = "London—Fanshawe" if constituencynumber == 35051
replace constituencyname = "London North Centre" if constituencynumber == 35052
replace constituencyname = "London West" if constituencynumber == 35053
replace constituencyname = "Markham—Stouffville" if constituencynumber == 35054
replace constituencyname = "Markham—Thornhill" if constituencynumber == 35055
replace constituencyname = "Markham—Unionville" if constituencynumber == 35056
replace constituencyname = "Milton" if constituencynumber == 35057
replace constituencyname = "Mississauga Centre" if constituencynumber == 35058
replace constituencyname = "Mississauga East—Cooksville" if constituencynumber == 35059
replace constituencyname = "Mississauga—Erin Mills" if constituencynumber == 35060
replace constituencyname = "Mississauga—Lakeshore" if constituencynumber == 35061
replace constituencyname = "Mississauga—Malton" if constituencynumber == 35062
replace constituencyname = "Mississauga—Streetsville" if constituencynumber == 35063
replace constituencyname = "Nepean" if constituencynumber == 35064
replace constituencyname = "Newmarket—Aurora" if constituencynumber == 35065
replace constituencyname = "Niagara Centre" if constituencynumber == 35066
replace constituencyname = "Niagara Falls" if constituencynumber == 35067
replace constituencyname = "Niagara West" if constituencynumber == 35068
replace constituencyname = "Nickel Belt" if constituencynumber == 35069
replace constituencyname = "Nipissing—Timiskaming" if constituencynumber == 35070
replace constituencyname = "Northumberland—Peterborough South" if constituencynumber == 35071
replace constituencyname = "Oakville" if constituencynumber == 35072
replace constituencyname = "Oakville North—Burlington" if constituencynumber == 35073
replace constituencyname = "Oshawa" if constituencynumber == 35074
replace constituencyname = "Ottawa Centre" if constituencynumber == 35075
replace constituencyname = "Orléans" if constituencynumber == 35076
replace constituencyname = "Ottawa South" if constituencynumber == 35077
replace constituencyname = "Ottawa—Vanier" if constituencynumber == 35078
replace constituencyname = "Ottawa West—Nepean" if constituencynumber == 35079
replace constituencyname = "Oxford" if constituencynumber == 35080
replace constituencyname = "Parkdale—High Park" if constituencynumber == 35081
replace constituencyname = "Parry Sound—Muskoka" if constituencynumber == 35082
replace constituencyname = "Perth—Wellington" if constituencynumber == 35083
replace constituencyname = "Peterborough—Kawartha" if constituencynumber == 35084
replace constituencyname = "Pickering—Uxbridge" if constituencynumber == 35085
replace constituencyname = "Renfrew—Nipissing—Pembroke" if constituencynumber == 35086
replace constituencyname = "Richmond Hill" if constituencynumber == 35087
replace constituencyname = "Carleton" if constituencynumber == 35088
replace constituencyname = "St. Catharines" if constituencynumber == 35089
replace constituencyname = "Toronto—St. Paul's" if constituencynumber == 35090
replace constituencyname = "Sarnia—Lambton" if constituencynumber == 35091
replace constituencyname = "Sault Ste. Marie" if constituencynumber == 35092
replace constituencyname = "Scarborough—Agincourt" if constituencynumber == 35093
replace constituencyname = "Scarborough Centre" if constituencynumber == 35094
replace constituencyname = "Scarborough—Guildwood" if constituencynumber == 35095
replace constituencyname = "Scarborough North" if constituencynumber == 35096
replace constituencyname = "Scarborough—Rouge Park" if constituencynumber == 35097
replace constituencyname = "Scarborough Southwest" if constituencynumber == 35098
replace constituencyname = "Simcoe—Grey" if constituencynumber == 35099
replace constituencyname = "Simcoe North" if constituencynumber == 35100
replace constituencyname = "Spadina—Fort York" if constituencynumber == 35101
replace constituencyname = "Stormont—Dundas—South Glengarry" if constituencynumber == 35102
replace constituencyname = "Sudbury" if constituencynumber == 35103
replace constituencyname = "Thornhill" if constituencynumber == 35104
replace constituencyname = "Thunder Bay—Rainy River" if constituencynumber == 35105
replace constituencyname = "Thunder Bay—Superior North" if constituencynumber == 35106
replace constituencyname = "Timmins—James Bay" if constituencynumber == 35107
replace constituencyname = "Toronto Centre" if constituencynumber == 35108
replace constituencyname = "Toronto—Danforth" if constituencynumber == 35109
replace constituencyname = "University—Rosedale" if constituencynumber == 35110
replace constituencyname = "Vaughan—Woodbridge" if constituencynumber == 35111
replace constituencyname = "Waterloo" if constituencynumber == 35112
replace constituencyname = "Wellington—Halton Hills" if constituencynumber == 35113
replace constituencyname = "Whitby" if constituencynumber == 35114
replace constituencyname = "Willowdale" if constituencynumber == 35115
replace constituencyname = "Windsor—Tecumseh" if constituencynumber == 35116
replace constituencyname = "Windsor West" if constituencynumber == 35117
replace constituencyname = "York Centre" if constituencynumber == 35118
replace constituencyname = "York—Simcoe" if constituencynumber == 35119
replace constituencyname = "York South—Weston" if constituencynumber == 35120
replace constituencyname = "Humber River—Black Creek" if constituencynumber == 35121
replace constituencyname = "Brandon—Souris" if constituencynumber == 46001
replace constituencyname = "Charleswood—St. James—Assiniboia—Headingley" if constituencynumber == 46002
replace constituencyname = "Churchill—Keewatinook Aski" if constituencynumber == 46003
replace constituencyname = "Dauphin—Swan River—Neepawa" if constituencynumber == 46004
replace constituencyname = "Elmwood—Transcona" if constituencynumber == 46005
replace constituencyname = "Kildonan—St. Paul" if constituencynumber == 46006
replace constituencyname = "Portage—Lisgar" if constituencynumber == 46007
replace constituencyname = "Provencher" if constituencynumber == 46008
replace constituencyname = "Saint Boniface—Saint Vital" if constituencynumber == 46009
replace constituencyname = "Selkirk—Interlake—Eastman" if constituencynumber == 46010
replace constituencyname = "Winnipeg Centre" if constituencynumber == 46011
replace constituencyname = "Winnipeg North" if constituencynumber == 46012
replace constituencyname = "Winnipeg South" if constituencynumber == 46013
replace constituencyname = "Winnipeg South Centre" if constituencynumber == 46014
replace constituencyname = "Battlefords—Lloydminster" if constituencynumber == 47001
replace constituencyname = "Cypress Hills—Grasslands" if constituencynumber == 47002
replace constituencyname = "Desnethé—Missinippi—Churchill River" if constituencynumber == 47003
replace constituencyname = "Carlton Trail—Eagle Creek" if constituencynumber == 47004
replace constituencyname = "Moose Jaw—Lake Centre—Lanigan" if constituencynumber == 47005
replace constituencyname = "Prince Albert" if constituencynumber == 47006
replace constituencyname = "Regina—Lewvan" if constituencynumber == 47007
replace constituencyname = "Regina—Qu'Appelle" if constituencynumber == 47008
replace constituencyname = "Regina—Wascana" if constituencynumber == 47009
replace constituencyname = "Saskatoon—Grasswood" if constituencynumber == 47010
replace constituencyname = "Saskatoon—University" if constituencynumber == 47011
replace constituencyname = "Saskatoon West" if constituencynumber == 47012
replace constituencyname = "Souris—Moose Mountain" if constituencynumber == 47013
replace constituencyname = "Yorkton—Melville" if constituencynumber == 47014
replace constituencyname = "Banff—Airdrie" if constituencynumber == 48001
replace constituencyname = "Battle River—Crowfoot" if constituencynumber == 48002
replace constituencyname = "Bow River" if constituencynumber == 48003
replace constituencyname = "Calgary Centre" if constituencynumber == 48004
replace constituencyname = "Calgary Confederation" if constituencynumber == 48005
replace constituencyname = "Calgary Forest Lawn" if constituencynumber == 48006
replace constituencyname = "Calgary Heritage" if constituencynumber == 48007
replace constituencyname = "Calgary Midnapore" if constituencynumber == 48008
replace constituencyname = "Calgary Nose Hill" if constituencynumber == 48009
replace constituencyname = "Calgary Rocky Ridge" if constituencynumber == 48010
replace constituencyname = "Calgary Shepard" if constituencynumber == 48011
replace constituencyname = "Calgary Signal Hill" if constituencynumber == 48012
replace constituencyname = "Calgary Skyview" if constituencynumber == 48013
replace constituencyname = "Edmonton Centre" if constituencynumber == 48014
replace constituencyname = "Edmonton Griesbach" if constituencynumber == 48015
replace constituencyname = "Edmonton Manning" if constituencynumber == 48016
replace constituencyname = "Edmonton Mill Woods" if constituencynumber == 48017
replace constituencyname = "Edmonton Riverbend" if constituencynumber == 48018
replace constituencyname = "Edmonton Strathcona" if constituencynumber == 48019
replace constituencyname = "Edmonton West" if constituencynumber == 48020
replace constituencyname = "Edmonton—Wetaskiwin" if constituencynumber == 48021
replace constituencyname = "Foothills" if constituencynumber == 48022
replace constituencyname = "Fort McMurray—Cold Lake" if constituencynumber == 48023
replace constituencyname = "Grande Prairie—Mackenzie" if constituencynumber == 48024
replace constituencyname = "Lakeland" if constituencynumber == 48025
replace constituencyname = "Lethbridge" if constituencynumber == 48026
replace constituencyname = "Medicine Hat—Cardston—Warner" if constituencynumber == 48027
replace constituencyname = "Peace River—Westlock" if constituencynumber == 48028
replace constituencyname = "Red Deer—Mountain View" if constituencynumber == 48029
replace constituencyname = "Red Deer—Lacombe" if constituencynumber == 48030
replace constituencyname = "St. Albert—Edmonton" if constituencynumber == 48031
replace constituencyname = "Sherwood Park—Fort Saskatchewan" if constituencynumber == 48032
replace constituencyname = "Sturgeon River—Parkland" if constituencynumber == 48033
replace constituencyname = "Yellowhead" if constituencynumber == 48034
replace constituencyname = "Abbotsford" if constituencynumber == 59001
replace constituencyname = "Burnaby North—Seymour" if constituencynumber == 59002
replace constituencyname = "Burnaby South" if constituencynumber == 59003
replace constituencyname = "Cariboo—Prince George" if constituencynumber == 59004
replace constituencyname = "Central Okanagan—Similkameen—Nicola" if constituencynumber == 59005
replace constituencyname = "Chilliwack—Hope" if constituencynumber == 59006
replace constituencyname = "Cloverdale—Langley City" if constituencynumber == 59007
replace constituencyname = "Coquitlam—Port Coquitlam" if constituencynumber == 59008
replace constituencyname = "Courtenay—Alberni" if constituencynumber == 59009
replace constituencyname = "Cowichan—Malahat—Langford" if constituencynumber == 59010
replace constituencyname = "Delta" if constituencynumber == 59011
replace constituencyname = "Fleetwood—Port Kells" if constituencynumber == 59012
replace constituencyname = "Kamloops—Thompson—Cariboo" if constituencynumber == 59013
replace constituencyname = "Kelowna—Lake Country" if constituencynumber == 59014
replace constituencyname = "Kootenay—Columbia" if constituencynumber == 59015
replace constituencyname = "Langley—Aldergrove" if constituencynumber == 59016
replace constituencyname = "Mission—Matsqui—Fraser Canyon" if constituencynumber == 59017
replace constituencyname = "Nanaimo—Ladysmith" if constituencynumber == 59018
replace constituencyname = "New Westminster—Burnaby" if constituencynumber == 59019
replace constituencyname = "North Okanagan—Shuswap" if constituencynumber == 59020
replace constituencyname = "North Vancouver" if constituencynumber == 59021
replace constituencyname = "Pitt Meadows—Maple Ridge" if constituencynumber == 59022
replace constituencyname = "Port Moody—Coquitlam" if constituencynumber == 59023
replace constituencyname = "Prince George—Peace River—Northern Rockies" if constituencynumber == 59024
replace constituencyname = "Richmond Centre" if constituencynumber == 59025
replace constituencyname = "Esquimalt—Saanich—Sooke" if constituencynumber == 59026
replace constituencyname = "Saanich—Gulf Islands" if constituencynumber == 59027
replace constituencyname = "Skeena—Bulkley Valley" if constituencynumber == 59028
replace constituencyname = "South Okanagan—West Kootenay" if constituencynumber == 59029
replace constituencyname = "South Surrey—White Rock" if constituencynumber == 59030
replace constituencyname = "Steveston—Richmond East" if constituencynumber == 59031
replace constituencyname = "Surrey Centre" if constituencynumber == 59032
replace constituencyname = "Surrey—Newton" if constituencynumber == 59033
replace constituencyname = "Vancouver Centre" if constituencynumber == 59034
replace constituencyname = "Vancouver East" if constituencynumber == 59035
replace constituencyname = "Vancouver Granville" if constituencynumber == 59036
replace constituencyname = "North Island—Powell River" if constituencynumber == 59037
replace constituencyname = "Vancouver Kingsway" if constituencynumber == 59038
replace constituencyname = "Vancouver Quadra" if constituencynumber == 59039
replace constituencyname = "Vancouver South" if constituencynumber == 59040
replace constituencyname = "Victoria" if constituencynumber == 59041
replace constituencyname = "West Vancouver—Sunshine Coast—Sea to Sky Country" if constituencynumber == 59042
replace constituencyname = "Yukon" if constituencynumber == 60001
replace constituencyname = "Northwest Territories" if constituencynumber == 61001
replace constituencyname = "Nunavut" if constituencynumber == 62001


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 15.2 if constituencynumber == 10001
replace margin = 6.200001 if constituencynumber == 10002
replace margin = 13 if constituencynumber == 10003
replace margin = 11.4 if constituencynumber == 10004
replace margin = 19.1 if constituencynumber == 10005
replace margin = 13.7 if constituencynumber == 10006
replace margin = 24.3 if constituencynumber == 10007
replace margin = 20.3 if constituencynumber == 11001
replace margin = 21 if constituencynumber == 11002
replace margin = 5.299999 if constituencynumber == 11003
replace margin = 14.9 if constituencynumber == 11004
replace margin = 4.400002 if constituencynumber == 12001
replace margin = 16.9 if constituencynumber == 12002
replace margin = 1 if constituencynumber == 12003
replace margin = 18.3 if constituencynumber == 12004
replace margin = 12.5 if constituencynumber == 12005
replace margin = 30.2 if constituencynumber == 12006
replace margin = 18.5 if constituencynumber == 12007
replace margin = 16.3 if constituencynumber == 12008
replace margin = 13.6 if constituencynumber == 12009
replace margin = 3.199999 if constituencynumber == 12010
replace margin = 2.899998 if constituencynumber == 12011
replace margin = 33.6 if constituencynumber == 13001
replace margin = 19.9 if constituencynumber == 13002
replace margin = 3.300001 if constituencynumber == 13003
replace margin = 20.4 if constituencynumber == 13004
replace margin = 21.9 if constituencynumber == 13005
replace margin = 1.099998 if constituencynumber == 13006
replace margin = 19.5 if constituencynumber == 13007
replace margin = 23.6 if constituencynumber == 13008
replace margin = 3.400002 if constituencynumber == 13009
replace margin = 25.1 if constituencynumber == 13010
replace margin = 7.799999 if constituencynumber == 24001
replace margin = 20.7 if constituencynumber == 24002
replace margin = 30.7 if constituencynumber == 24003
replace margin = 19.3 if constituencynumber == 24004
replace margin = 1.5 if constituencynumber == 24005
replace margin = 17.5 if constituencynumber == 24006
replace margin = 10.2 if constituencynumber == 24007
replace margin = 3.900002 if constituencynumber == 24008
replace margin = 38.9 if constituencynumber == 24009
replace margin = 27.2 if constituencynumber == 24010
replace margin = 27.4 if constituencynumber == 24011
replace margin = 2.599998 if constituencynumber == 24012
replace margin = 6 if constituencynumber == 24013
replace margin = 22.5 if constituencynumber == 24014
replace margin = 35.2 if constituencynumber == 24015
replace margin = 3.799999 if constituencynumber == 24016
replace margin = 34.3 if constituencynumber == 24017
replace margin = 9.299999 if constituencynumber == 24018
replace margin = 10.8 if constituencynumber == 24019
replace margin = 6.700001 if constituencynumber == 24020
replace margin = 1.200001 if constituencynumber == 24021
replace margin = 1.899998 if constituencynumber == 24022
replace margin = 5.4 if constituencynumber == 24023
replace margin = 35.8 if constituencynumber == 24024
replace margin = 27.4 if constituencynumber == 24025
replace margin = 1.700001 if constituencynumber == 24026
replace margin = 30.7 if constituencynumber == 24027
replace margin = .7000008 if constituencynumber == 24028
replace margin = 38.9 if constituencynumber == 24029
replace margin = 39.5 if constituencynumber == 24030
replace margin = 35.7 if constituencynumber == 24031
replace margin = 11 if constituencynumber == 24032
replace margin = 16.4 if constituencynumber == 24033
replace margin = 5.200001 if constituencynumber == 24034
replace margin = 18.9 if constituencynumber == 24035
replace margin = 42.9 if constituencynumber == 24036
replace margin = 19.4 if constituencynumber == 24037
replace margin = 13.7 if constituencynumber == 24038
replace margin = 16.6 if constituencynumber == 24039
replace margin = 27.6 if constituencynumber == 24040
replace margin = 2.5 if constituencynumber == 24041
replace margin = 19.5 if constituencynumber == 24042
replace margin = 4.299999 if constituencynumber == 24043
replace margin = 12.5 if constituencynumber == 24044
replace margin = 22.3 if constituencynumber == 24045
replace margin = 34.6 if constituencynumber == 24046
replace margin = 23.4 if constituencynumber == 24047
replace margin = 26.2 if constituencynumber == 24048
replace margin = 7.200001 if constituencynumber == 24049
replace margin = 37.6 if constituencynumber == 24050
replace margin = 9.400002 if constituencynumber == 24051
replace margin = 31.4 if constituencynumber == 24052
replace margin = 40.9 if constituencynumber == 24053
replace margin = 26.1 if constituencynumber == 24054
replace margin = 31.9 if constituencynumber == 24055
replace margin = 38.7 if constituencynumber == 24056
replace margin = 32.1 if constituencynumber == 24057
replace margin = 19.2 if constituencynumber == 24058
replace margin = .5999985 if constituencynumber == 24059
replace margin = 25.5 if constituencynumber == 24060
replace margin = 17.1 if constituencynumber == 24061
replace margin = 4.5 if constituencynumber == 24062
replace margin = 29.7 if constituencynumber == 24063
replace margin = 18.3 if constituencynumber == 24064
replace margin = 12.1 if constituencynumber == 24065
replace margin = 20.1 if constituencynumber == 24066
replace margin = 14.2 if constituencynumber == 24067
replace margin = 41.2 if constituencynumber == 24068
replace margin = 49.4 if constituencynumber == 24069
replace margin = 5.399998 if constituencynumber == 24070
replace margin = 18 if constituencynumber == 24071
replace margin = 1.5 if constituencynumber == 24072
replace margin = 1 if constituencynumber == 24073
replace margin = 22.9 if constituencynumber == 24074
replace margin = 21.3 if constituencynumber == 24075
replace margin = 2.4 if constituencynumber == 24076
replace margin = 37.7 if constituencynumber == 24077
replace margin = 19.9 if constituencynumber == 24078
replace margin = 31.7 if constituencynumber == 35001
replace margin = 15.4 if constituencynumber == 35002
replace margin = 2 if constituencynumber == 35003
replace margin = 14.5 if constituencynumber == 35004
replace margin = 7.799999 if constituencynumber == 35005
replace margin = 2.400002 if constituencynumber == 35006
replace margin = 35.8 if constituencynumber == 35007
replace margin = 20.3 if constituencynumber == 35008
replace margin = 21.1 if constituencynumber == 35009
replace margin = 23.7 if constituencynumber == 35010
replace margin = 21.1 if constituencynumber == 35011
replace margin = 29.6 if constituencynumber == 35012
replace margin = 9.599998 if constituencynumber == 35013
replace margin = 16 if constituencynumber == 35014
replace margin = 15.4 if constituencynumber == 35015
replace margin = 9.5 if constituencynumber == 35016
replace margin = 15.7 if constituencynumber == 35017
replace margin = 2.700001 if constituencynumber == 35018
replace margin = 35.9 if constituencynumber == 35019
replace margin = 15 if constituencynumber == 35020
replace margin = 24.6 if constituencynumber == 35021
replace margin = 9 if constituencynumber == 35022
replace margin = 9.899998 if constituencynumber == 35023
replace margin = 20.2 if constituencynumber == 35024
replace margin = 27 if constituencynumber == 35025
replace margin = 6.800003 if constituencynumber == 35026
replace margin = 17.4 if constituencynumber == 35027
replace margin = 23.2 if constituencynumber == 35028
replace margin = 39.2 if constituencynumber == 35029
replace margin = 2.600002 if constituencynumber == 35030
replace margin = 11.6 if constituencynumber == 35031
replace margin = 14.9 if constituencynumber == 35032
replace margin = 22.3 if constituencynumber == 35033
replace margin = 23.1 if constituencynumber == 35034
replace margin = 17.5 if constituencynumber == 35035
replace margin = 9.999998 if constituencynumber == 35036
replace margin = 5.799999 if constituencynumber == 35037
replace margin = 19.9 if constituencynumber == 35038
replace margin = 4.300003 if constituencynumber == 35039
replace margin = 15.4 if constituencynumber == 35040
replace margin = 6.599998 if constituencynumber == 35041
replace margin = 4 if constituencynumber == 35042
replace margin = 1.799999 if constituencynumber == 35043
replace margin = 22.5 if constituencynumber == 35044
replace margin = 10.7 if constituencynumber == 35045
replace margin = .7000008 if constituencynumber == 35046
replace margin = 6.700001 if constituencynumber == 35047
replace margin = 23.6 if constituencynumber == 35048
replace margin = 23.4 if constituencynumber == 35049
replace margin = 22.5 if constituencynumber == 35050
replace margin = 13.9 if constituencynumber == 35051
replace margin = 19.1 if constituencynumber == 35052
replace margin = 15.1 if constituencynumber == 35053
replace margin = 8.300001 if constituencynumber == 35054
replace margin = 19.3 if constituencynumber == 35055
replace margin = 10.5 if constituencynumber == 35056
replace margin = 15.6 if constituencynumber == 35057
replace margin = 26.3 if constituencynumber == 35058
replace margin = 19.5 if constituencynumber == 35059
replace margin = 20.8 if constituencynumber == 35060
replace margin = 11.1 if constituencynumber == 35061
replace margin = 31.7 if constituencynumber == 35062
replace margin = 17.3 if constituencynumber == 35063
replace margin = 12.4 if constituencynumber == 35064
replace margin = 5.299999 if constituencynumber == 35065
replace margin = 4 if constituencynumber == 35066
replace margin = 3 if constituencynumber == 35067
replace margin = 13 if constituencynumber == 35068
replace margin = 6.900002 if constituencynumber == 35069
replace margin = 13.3 if constituencynumber == 35070
replace margin = 3.5 if constituencynumber == 35071
replace margin = 7.200001 if constituencynumber == 35072
replace margin = 10.3 if constituencynumber == 35073
replace margin = 10.4 if constituencynumber == 35074
replace margin = 19.7 if constituencynumber == 35075
replace margin = 26.1 if constituencynumber == 35076
replace margin = 27.8 if constituencynumber == 35077
replace margin = 30 if constituencynumber == 35078
replace margin = 18.5 if constituencynumber == 35079
replace margin = 27.9 if constituencynumber == 35080
replace margin = 15.9 if constituencynumber == 35081
replace margin = 11.4 if constituencynumber == 35082
replace margin = 19.2 if constituencynumber == 35083
replace margin = 4.399998 if constituencynumber == 35084
replace margin = 21.9 if constituencynumber == 35085
replace margin = 33.1 if constituencynumber == 35086
replace margin = .4000015 if constituencynumber == 35087
replace margin = 8.099998 if constituencynumber == 35088
replace margin = 8.6 if constituencynumber == 35089
replace margin = 32.7 if constituencynumber == 35090
replace margin = 27.6 if constituencynumber == 35091
replace margin = 6.899998 if constituencynumber == 35092
replace margin = 13.5 if constituencynumber == 35093
replace margin = 32.9 if constituencynumber == 35094
replace margin = 38.7 if constituencynumber == 35095
replace margin = 23.3 if constituencynumber == 35096
replace margin = 42.1 if constituencynumber == 35097
replace margin = 36.5 if constituencynumber == 35098
replace margin = 11.8 if constituencynumber == 35099
replace margin = 12.6 if constituencynumber == 35100
replace margin = 35.7 if constituencynumber == 35101
replace margin = 28.3 if constituencynumber == 35102
replace margin = 12 if constituencynumber == 35103
replace margin = 19.2 if constituencynumber == 35104
replace margin = 6 if constituencynumber == 35105
replace margin = 17.3 if constituencynumber == 35106
replace margin = 13.5 if constituencynumber == 35107
replace margin = 35.1 if constituencynumber == 35108
replace margin = 14.5 if constituencynumber == 35109
replace margin = 29.8 if constituencynumber == 35110
replace margin = 15 if constituencynumber == 35111
replace margin = 24.3 if constituencynumber == 35112
replace margin = 19 if constituencynumber == 35113
replace margin = 8.200001 if constituencynumber == 35114
replace margin = 12.8 if constituencynumber == 35115
replace margin = 1.100002 if constituencynumber == 35116
replace margin = 3.700001 if constituencynumber == 35117
replace margin = 13.5 if constituencynumber == 35118
replace margin = 19.5 if constituencynumber == 35119
replace margin = 39.5 if constituencynumber == 35120
replace margin = 42.1 if constituencynumber == 35121
replace margin = 49.4 if constituencynumber == 46001
replace margin = 5.200001 if constituencynumber == 46002
replace margin = 26.6 if constituencynumber == 46003
replace margin = 50.2 if constituencynumber == 46004
replace margin = 8.099998 if constituencynumber == 46005
replace margin = 16.9 if constituencynumber == 46006
replace margin = 60.1 if constituencynumber == 46007
replace margin = 52.8 if constituencynumber == 46008
replace margin = 10.3 if constituencynumber == 46009
replace margin = 44.8 if constituencynumber == 46010
replace margin = 7.5 if constituencynumber == 46011
replace margin = 21.7 if constituencynumber == 46012
replace margin = 3.399998 if constituencynumber == 46013
replace margin = 15.3 if constituencynumber == 46014
replace margin = 66.9 if constituencynumber == 47001
replace margin = 71.6 if constituencynumber == 47002
replace margin = 13.9 if constituencynumber == 47003
replace margin = 66.3 if constituencynumber == 47004
replace margin = 54.1 if constituencynumber == 47005
replace margin = 50.3 if constituencynumber == 47006
replace margin = 23.9 if constituencynumber == 47007
replace margin = 43.3 if constituencynumber == 47008
replace margin = 15.8 if constituencynumber == 47009
replace margin = 27.7 if constituencynumber == 47010
replace margin = 22.3 if constituencynumber == 47011
replace margin = 7.400002 if constituencynumber == 47012
replace margin = 76.7 if constituencynumber == 47013
replace margin = 64 if constituencynumber == 47014
replace margin = 60.3 if constituencynumber == 48001
replace margin = 80.4 if constituencynumber == 48002
replace margin = 78.1 if constituencynumber == 48003
replace margin = 29.6 if constituencynumber == 48004
replace margin = 32.5 if constituencynumber == 48005
replace margin = 37.9 if constituencynumber == 48006
replace margin = 56.7 if constituencynumber == 48007
replace margin = 63.3 if constituencynumber == 48008
replace margin = 54.1 if constituencynumber == 48009
replace margin = 49.9 if constituencynumber == 48010
replace margin = 63.9 if constituencynumber == 48011
replace margin = 54.7 if constituencynumber == 48012
replace margin = 24.2 if constituencynumber == 48013
replace margin = 8.400002 if constituencynumber == 48014
replace margin = 26.3 if constituencynumber == 48015
replace margin = 34.4 if constituencynumber == 48016
replace margin = 16.7 if constituencynumber == 48017
replace margin = 34.4 if constituencynumber == 48018
replace margin = 10.2 if constituencynumber == 48019
replace margin = 40.8 if constituencynumber == 48020
replace margin = 60 if constituencynumber == 48021
replace margin = 76.2 if constituencynumber == 48022
replace margin = 70.4 if constituencynumber == 48023
replace margin = 77 if constituencynumber == 48024
replace margin = 77.4 if constituencynumber == 48025
replace margin = 51.1 if constituencynumber == 48026
replace margin = 70.5 if constituencynumber == 48027
replace margin = 73.2 if constituencynumber == 48028
replace margin = 73 if constituencynumber == 48029
replace margin = 70.9 if constituencynumber == 48030
replace margin = 41.5 if constituencynumber == 48031
replace margin = 61.3 if constituencynumber == 48032
replace margin = 67.4 if constituencynumber == 48033
replace margin = 75.1 if constituencynumber == 48034
replace margin = 29.8 if constituencynumber == 59001
replace margin = 3.200001 if constituencynumber == 59002
replace margin = 6.800001 if constituencynumber == 59003
replace margin = 32.7 if constituencynumber == 59004
replace margin = 22.9 if constituencynumber == 59005
replace margin = 29.4 if constituencynumber == 59006
replace margin = 2.5 if constituencynumber == 59007
replace margin = .7000008 if constituencynumber == 59008
replace margin = 8.100002 if constituencynumber == 59009
replace margin = 10.1 if constituencynumber == 59010
replace margin = 8.200001 if constituencynumber == 59011
replace margin = 3.799999 if constituencynumber == 59012
replace margin = 17.5 if constituencynumber == 59013
replace margin = 12.9 if constituencynumber == 59014
replace margin = 10.4 if constituencynumber == 59015
replace margin = 21.4 if constituencynumber == 59016
replace margin = 15.7 if constituencynumber == 59017
replace margin = 8.699999 if constituencynumber == 59018
replace margin = 20.8 if constituencynumber == 59019
replace margin = 26.2 if constituencynumber == 59020
replace margin = 16 if constituencynumber == 59021
replace margin = 6.5 if constituencynumber == 59022
replace margin = .3000011 if constituencynumber == 59023
replace margin = 58.2 if constituencynumber == 59024
replace margin = 20.5 if constituencynumber == 59025
replace margin = 7.699999 if constituencynumber == 59026
replace margin = 28.9 if constituencynumber == 59027
replace margin = 7.700001 if constituencynumber == 59028
replace margin = 1.200001 if constituencynumber == 59029
replace margin = 4.5 if constituencynumber == 59030
replace margin = 6.600002 if constituencynumber == 59031
replace margin = 9.900002 if constituencynumber == 59032
replace margin = 15.8 if constituencynumber == 59033
replace margin = 18.5 if constituencynumber == 59034
replace margin = 34.5 if constituencynumber == 59035
replace margin = 5.999998 if constituencynumber == 59036
replace margin = 5.300003 if constituencynumber == 59037
replace margin = 26 if constituencynumber == 59038
replace margin = 15.8 if constituencynumber == 59039
replace margin = 7.900002 if constituencynumber == 59040
replace margin = 3.300001 if constituencynumber == 59041
replace margin = 8.200001 if constituencynumber == 59042
replace margin = .7999992 if constituencynumber == 60001
replace margin = 14.2 if constituencynumber == 61001
replace margin = 9.9 if constituencynumber == 62001

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.907526 if constituencynumber == 10001
replace enep = 2.630783 if constituencynumber == 10002
replace enep = 2.667563 if constituencynumber == 10003
replace enep = 2.960586 if constituencynumber == 10004
replace enep = 2.895906 if constituencynumber == 10005
replace enep = 2.752773 if constituencynumber == 10006
replace enep = 2.703996 if constituencynumber == 10007
replace enep = 2.850603 if constituencynumber == 11001
replace enep = 3.285454 if constituencynumber == 11002
replace enep = 3.136074 if constituencynumber == 11003
replace enep = 3.211489 if constituencynumber == 11004
replace enep = 3.345287 if constituencynumber == 12001
replace enep = 3.038812 if constituencynumber == 12002
replace enep = 3.399406 if constituencynumber == 12003
replace enep = 3.183497 if constituencynumber == 12004
replace enep = 3.279183 if constituencynumber == 12005
replace enep = 2.995994 if constituencynumber == 12006
replace enep = 3.393028 if constituencynumber == 12007
replace enep = 3.527175 if constituencynumber == 12008
replace enep = 3.426746 if constituencynumber == 12009
replace enep = 4.247799 if constituencynumber == 12010
replace enep = 3.178599 if constituencynumber == 12011
replace enep = 2.640111 if constituencynumber == 13001
replace enep = 3.089414 if constituencynumber == 13002
replace enep = 3.509191 if constituencynumber == 13003
replace enep = 3.22409 if constituencynumber == 13004
replace enep = 2.778071 if constituencynumber == 13005
replace enep = 3.509215 if constituencynumber == 13006
replace enep = 3.4846 if constituencynumber == 13007
replace enep = 3.011676 if constituencynumber == 13008
replace enep = 3.54134 if constituencynumber == 13009
replace enep = 2.913244 if constituencynumber == 13010
replace enep = 3.899396 if constituencynumber == 24001
replace enep = 3.302194 if constituencynumber == 24002
replace enep = 2.908397 if constituencynumber == 24003
replace enep = 3.027697 if constituencynumber == 24004
replace enep = 3.36226 if constituencynumber == 24005
replace enep = 2.583525 if constituencynumber == 24006
replace enep = 3.786775 if constituencynumber == 24007
replace enep = 4.1287 if constituencynumber == 24008
replace enep = 2.611627 if constituencynumber == 24009
replace enep = 2.982929 if constituencynumber == 24010
replace enep = 2.980431 if constituencynumber == 24011
replace enep = 3.402066 if constituencynumber == 24012
replace enep = 3.135425 if constituencynumber == 24013
replace enep = 2.816235 if constituencynumber == 24014
replace enep = 2.534366 if constituencynumber == 24015
replace enep = 3.45681 if constituencynumber == 24016
replace enep = 2.837596 if constituencynumber == 24017
replace enep = 3.555733 if constituencynumber == 24018
replace enep = 3.68411 if constituencynumber == 24019
replace enep = 3.712393 if constituencynumber == 24020
replace enep = 3.271181 if constituencynumber == 24021
replace enep = 3.426676 if constituencynumber == 24022
replace enep = 3.650288 if constituencynumber == 24023
replace enep = 2.965344 if constituencynumber == 24024
replace enep = 3.507258 if constituencynumber == 24025
replace enep = 2.806608 if constituencynumber == 24026
replace enep = 2.926304 if constituencynumber == 24027
replace enep = 3.601475 if constituencynumber == 24028
replace enep = 2.497921 if constituencynumber == 24029
replace enep = 2.891527 if constituencynumber == 24030
replace enep = 2.491901 if constituencynumber == 24031
replace enep = 3.895674 if constituencynumber == 24032
replace enep = 3.032785 if constituencynumber == 24033
replace enep = 3.081541 if constituencynumber == 24034
replace enep = 3.19501 if constituencynumber == 24035
replace enep = 2.597686 if constituencynumber == 24036
replace enep = 3.51881 if constituencynumber == 24037
replace enep = 2.935177 if constituencynumber == 24038
replace enep = 3.393811 if constituencynumber == 24039
replace enep = 3.211768 if constituencynumber == 24040
replace enep = 3.279818 if constituencynumber == 24041
replace enep = 3.362882 if constituencynumber == 24042
replace enep = 3.457432 if constituencynumber == 24043
replace enep = 3.552221 if constituencynumber == 24044
replace enep = 3.346104 if constituencynumber == 24045
replace enep = 2.724231 if constituencynumber == 24046
replace enep = 2.979205 if constituencynumber == 24047
replace enep = 2.933894 if constituencynumber == 24048
replace enep = 3.082082 if constituencynumber == 24049
replace enep = 2.548992 if constituencynumber == 24050
replace enep = 3.225682 if constituencynumber == 24051
replace enep = 2.560479 if constituencynumber == 24052
replace enep = 2.721348 if constituencynumber == 24053
replace enep = 3.426394 if constituencynumber == 24054
replace enep = 3.021796 if constituencynumber == 24055
replace enep = 2.706118 if constituencynumber == 24056
replace enep = 3.244741 if constituencynumber == 24057
replace enep = 3.40791 if constituencynumber == 24058
replace enep = 3.896463 if constituencynumber == 24059
replace enep = 2.693124 if constituencynumber == 24060
replace enep = 3.196032 if constituencynumber == 24061
replace enep = 3.204687 if constituencynumber == 24062
replace enep = 2.922626 if constituencynumber == 24063
replace enep = 3.334378 if constituencynumber == 24064
replace enep = 3.11379 if constituencynumber == 24065
replace enep = 3.666576 if constituencynumber == 24066
replace enep = 3.180864 if constituencynumber == 24067
replace enep = 2.551164 if constituencynumber == 24068
replace enep = 2.447016 if constituencynumber == 24069
replace enep = 3.285421 if constituencynumber == 24070
replace enep = 3.005349 if constituencynumber == 24071
replace enep = 3.250003 if constituencynumber == 24072
replace enep = 4.055529 if constituencynumber == 24073
replace enep = 3.217979 if constituencynumber == 24074
replace enep = 2.819054 if constituencynumber == 24075
replace enep = 4.141661 if constituencynumber == 24076
replace enep = 2.930377 if constituencynumber == 24077
replace enep = 3.074359 if constituencynumber == 24078
replace enep = 2.409894 if constituencynumber == 35001
replace enep = 3.287765 if constituencynumber == 35002
replace enep = 2.604322 if constituencynumber == 35003
replace enep = 3.199805 if constituencynumber == 35004
replace enep = 3.462208 if constituencynumber == 35005
replace enep = 3.136674 if constituencynumber == 35006
replace enep = 2.521642 if constituencynumber == 35007
replace enep = 2.976049 if constituencynumber == 35008
replace enep = 2.847543 if constituencynumber == 35009
replace enep = 2.699157 if constituencynumber == 35010
replace enep = 2.82269 if constituencynumber == 35011
replace enep = 2.646203 if constituencynumber == 35012
replace enep = 3.333256 if constituencynumber == 35013
replace enep = 3.073377 if constituencynumber == 35014
replace enep = 2.767408 if constituencynumber == 35015
replace enep = 3.449073 if constituencynumber == 35016
replace enep = 2.919486 if constituencynumber == 35017
replace enep = 2.703887 if constituencynumber == 35018
replace enep = 2.33321 if constituencynumber == 35019
replace enep = 2.567941 if constituencynumber == 35020
replace enep = 2.403893 if constituencynumber == 35021
replace enep = 3.220602 if constituencynumber == 35022
replace enep = 3.150946 if constituencynumber == 35023
replace enep = 2.48351 if constituencynumber == 35024
replace enep = 2.930686 if constituencynumber == 35025
replace enep = 3.043584 if constituencynumber == 35026
replace enep = 2.522723 if constituencynumber == 35027
replace enep = 2.705159 if constituencynumber == 35028
replace enep = 2.276053 if constituencynumber == 35029
replace enep = 3.136546 if constituencynumber == 35030
replace enep = 2.714581 if constituencynumber == 35031
replace enep = 3.560328 if constituencynumber == 35032
replace enep = 3.226015 if constituencynumber == 35033
replace enep = 2.961147 if constituencynumber == 35034
replace enep = 3.098556 if constituencynumber == 35035
replace enep = 3.357136 if constituencynumber == 35036
replace enep = 3.443965 if constituencynumber == 35037
replace enep = 3.070706 if constituencynumber == 35038
replace enep = 3.025105 if constituencynumber == 35039
replace enep = 2.762965 if constituencynumber == 35040
replace enep = 2.948435 if constituencynumber == 35041
replace enep = 3.447301 if constituencynumber == 35042
replace enep = 2.530012 if constituencynumber == 35043
replace enep = 3.218798 if constituencynumber == 35044
replace enep = 3.675403 if constituencynumber == 35045
replace enep = 3.036274 if constituencynumber == 35046
replace enep = 3.292018 if constituencynumber == 35047
replace enep = 2.987804 if constituencynumber == 35048
replace enep = 3.075797 if constituencynumber == 35049
replace enep = 2.958947 if constituencynumber == 35050
replace enep = 3.297566 if constituencynumber == 35051
replace enep = 3.34295 if constituencynumber == 35052
replace enep = 3.207616 if constituencynumber == 35053
replace enep = 3.41774 if constituencynumber == 35054
replace enep = 2.401248 if constituencynumber == 35055
replace enep = 2.543144 if constituencynumber == 35056
replace enep = 2.474935 if constituencynumber == 35057
replace enep = 2.445903 if constituencynumber == 35058
replace enep = 2.477369 if constituencynumber == 35059
replace enep = 2.482967 if constituencynumber == 35060
replace enep = 2.612979 if constituencynumber == 35061
replace enep = 2.416364 if constituencynumber == 35062
replace enep = 2.656311 if constituencynumber == 35063
replace enep = 2.905794 if constituencynumber == 35064
replace enep = 2.908778 if constituencynumber == 35065
replace enep = 3.414216 if constituencynumber == 35066
replace enep = 3.678418 if constituencynumber == 35067
replace enep = 3.036883 if constituencynumber == 35068
replace enep = 3.294057 if constituencynumber == 35069
replace enep = 3.48477 if constituencynumber == 35070
replace enep = 3.176469 if constituencynumber == 35071
replace enep = 2.657652 if constituencynumber == 35072
replace enep = 2.586452 if constituencynumber == 35073
replace enep = 3.332589 if constituencynumber == 35074
replace enep = 2.91757 if constituencynumber == 35075
replace enep = 2.562907 if constituencynumber == 35076
replace enep = 2.75923 if constituencynumber == 35077
replace enep = 2.912828 if constituencynumber == 35078
replace enep = 3.119872 if constituencynumber == 35079
replace enep = 3.15861 if constituencynumber == 35080
replace enep = 2.893929 if constituencynumber == 35081
replace enep = 3.283059 if constituencynumber == 35082
replace enep = 3.148109 if constituencynumber == 35083
replace enep = 3.22193 if constituencynumber == 35084
replace enep = 2.755261 if constituencynumber == 35085
replace enep = 2.918149 if constituencynumber == 35086
replace enep = 2.604201 if constituencynumber == 35087
replace enep = 2.692051 if constituencynumber == 35088
replace enep = 3.244372 if constituencynumber == 35089
replace enep = 2.69311 if constituencynumber == 35090
replace enep = 2.963112 if constituencynumber == 35091
replace enep = 3.223031 if constituencynumber == 35092
replace enep = 2.498358 if constituencynumber == 35093
replace enep = 2.684535 if constituencynumber == 35094
replace enep = 2.287654 if constituencynumber == 35095
replace enep = 2.52378 if constituencynumber == 35096
replace enep = 2.25858 if constituencynumber == 35097
replace enep = 2.521254 if constituencynumber == 35098
replace enep = 3.168257 if constituencynumber == 35099
replace enep = 3.202193 if constituencynumber == 35100
replace enep = 2.593563 if constituencynumber == 35101
replace enep = 2.64138 if constituencynumber == 35102
replace enep = 3.354613 if constituencynumber == 35103
replace enep = 2.333319 if constituencynumber == 35104
replace enep = 3.36148 if constituencynumber == 35105
replace enep = 3.317278 if constituencynumber == 35106
replace enep = 3.275617 if constituencynumber == 35107
replace enep = 2.506806 if constituencynumber == 35108
replace enep = 2.831538 if constituencynumber == 35109
replace enep = 2.864164 if constituencynumber == 35110
replace enep = 2.487587 if constituencynumber == 35111
replace enep = 3.021413 if constituencynumber == 35112
replace enep = 3.024858 if constituencynumber == 35113
replace enep = 2.941739 if constituencynumber == 35114
replace enep = 2.622428 if constituencynumber == 35115
replace enep = 3.388613 if constituencynumber == 35116
replace enep = 3.037667 if constituencynumber == 35117
replace enep = 2.516856 if constituencynumber == 35118
replace enep = 3.178791 if constituencynumber == 35119
replace enep = 2.4471 if constituencynumber == 35120
replace enep = 2.292316 if constituencynumber == 35121
replace enep = 2.255793 if constituencynumber == 46001
replace enep = 3.165348 if constituencynumber == 46002
replace enep = 2.847162 if constituencynumber == 46003
replace enep = 2.201445 if constituencynumber == 46004
replace enep = 2.739801 if constituencynumber == 46005
replace enep = 3.074218 if constituencynumber == 46006
replace enep = 1.907931 if constituencynumber == 46007
replace enep = 2.119048 if constituencynumber == 46008
replace enep = 3.100458 if constituencynumber == 46009
replace enep = 2.254852 if constituencynumber == 46010
replace enep = 3.155261 if constituencynumber == 46011
replace enep = 2.959009 if constituencynumber == 46012
replace enep = 2.87141 if constituencynumber == 46013
replace enep = 3.066243 if constituencynumber == 46014
replace enep = 1.583978 if constituencynumber == 47001
replace enep = 1.493226 if constituencynumber == 47002
replace enep = 3.027789 if constituencynumber == 47003
replace enep = 1.572846 if constituencynumber == 47004
replace enep = 1.853286 if constituencynumber == 47005
replace enep = 1.999716 if constituencynumber == 47006
replace enep = 2.654886 if constituencynumber == 47007
replace enep = 2.21078 if constituencynumber == 47008
replace enep = 2.671896 if constituencynumber == 47009
replace enep = 2.635393 if constituencynumber == 47010
replace enep = 2.641743 if constituencynumber == 47011
replace enep = 2.52273 if constituencynumber == 47012
replace enep = 1.387912 if constituencynumber == 47013
replace enep = 1.663938 if constituencynumber == 47014
replace enep = 1.882778 if constituencynumber == 48001
replace enep = 1.357383 if constituencynumber == 48002
replace enep = 1.405904 if constituencynumber == 48003
replace enep = 2.468368 if constituencynumber == 48004
replace enep = 2.667407 if constituencynumber == 48005
replace enep = 2.406693 if constituencynumber == 48006
replace enep = 1.889141 if constituencynumber == 48007
replace enep = 1.740511 if constituencynumber == 48008
replace enep = 1.914777 if constituencynumber == 48009
replace enep = 1.96554 if constituencynumber == 48010
replace enep = 1.712992 if constituencynumber == 48011
replace enep = 1.915643 if constituencynumber == 48012
replace enep = 2.642476 if constituencynumber == 48013
replace enep = 3.089719 if constituencynumber == 48014
replace enep = 2.793327 if constituencynumber == 48015
replace enep = 2.559921 if constituencynumber == 48016
replace enep = 2.623226 if constituencynumber == 48017
replace enep = 2.458077 if constituencynumber == 48018
replace enep = 2.662974 if constituencynumber == 48019
replace enep = 2.306358 if constituencynumber == 48020
replace enep = 1.809022 if constituencynumber == 48021
replace enep = 1.464523 if constituencynumber == 48022
replace enep = 1.533617 if constituencynumber == 48023
replace enep = 1.401068 if constituencynumber == 48024
replace enep = 1.40611 if constituencynumber == 48025
replace enep = 2.107895 if constituencynumber == 48026
replace enep = 1.561575 if constituencynumber == 48027
replace enep = 1.509924 if constituencynumber == 48028
replace enep = 1.525099 if constituencynumber == 48029
replace enep = 1.540118 if constituencynumber == 48030
replace enep = 2.328945 if constituencynumber == 48031
replace enep = 1.771724 if constituencynumber == 48032
replace enep = 1.621568 if constituencynumber == 48033
replace enep = 1.464176 if constituencynumber == 48034
replace enep = 2.893309 if constituencynumber == 59001
replace enep = 3.600606 if constituencynumber == 59002
replace enep = 3.361333 if constituencynumber == 59003
replace enep = 2.855136 if constituencynumber == 59004
replace enep = 3.060921 if constituencynumber == 59005
replace enep = 3.072962 if constituencynumber == 59006
replace enep = 3.26649 if constituencynumber == 59007
replace enep = 3.403467 if constituencynumber == 59008
replace enep = 3.208265 if constituencynumber == 59009
replace enep = 3.788539 if constituencynumber == 59010
replace enep = 3.229933 if constituencynumber == 59011
replace enep = 3.282639 if constituencynumber == 59012
replace enep = 3.252255 if constituencynumber == 59013
replace enep = 2.980981 if constituencynumber == 59014
replace enep = 2.975951 if constituencynumber == 59015
replace enep = 3.114353 if constituencynumber == 59016
replace enep = 3.396139 if constituencynumber == 59017
replace enep = 3.831961 if constituencynumber == 59018
replace enep = 3.289885 if constituencynumber == 59019
replace enep = 3.080772 if constituencynumber == 59020
replace enep = 3.343453 if constituencynumber == 59021
replace enep = 3.533269 if constituencynumber == 59022
replace enep = 3.534618 if constituencynumber == 59023
replace enep = 1.945082 if constituencynumber == 59024
replace enep = 2.887737 if constituencynumber == 59025
replace enep = 3.924986 if constituencynumber == 59026
replace enep = 3.069688 if constituencynumber == 59027
replace enep = 3.346138 if constituencynumber == 59028
replace enep = 3.407457 if constituencynumber == 59029
replace enep = 2.984656 if constituencynumber == 59030
replace enep = 3.076421 if constituencynumber == 59031
replace enep = 3.517708 if constituencynumber == 59032
replace enep = 3.001705 if constituencynumber == 59033
replace enep = 3.480016 if constituencynumber == 59034
replace enep = 2.89553 if constituencynumber == 59035
replace enep = 4.084651 if constituencynumber == 59036
replace enep = 3.480573 if constituencynumber == 59037
replace enep = 2.959307 if constituencynumber == 59038
replace enep = 3.287268 if constituencynumber == 59039
replace enep = 3.138515 if constituencynumber == 59040
replace enep = 3.767656 if constituencynumber == 59041
replace enep = 3.804364 if constituencynumber == 59042
replace enep = 3.587122 if constituencynumber == 60001
replace enep = 3.522082 if constituencynumber == 61001
replace enep = 3.025261 if constituencynumber == 62001

* Competition measure

gen competition = .

replace competition = .4283795 if constituencynumber == 10001
replace competition = .2522675 if constituencynumber == 10002
replace competition = .3003395 if constituencynumber == 10003
replace competition = .325148 if constituencynumber == 10004
replace competition = .3233915 if constituencynumber == 10005
replace competition = .119774 if constituencynumber == 10006
replace competition = .2300315 if constituencynumber == 10007
replace competition = .389268 if constituencynumber == 11001
replace competition = .39063 if constituencynumber == 11002
replace competition = .3456155 if constituencynumber == 11003
replace competition = .3995195 if constituencynumber == 11004
replace competition = .31928 if constituencynumber == 12001
replace competition = .3663995 if constituencynumber == 12002
replace competition = .331228 if constituencynumber == 12003
replace competition = .369294 if constituencynumber == 12004
replace competition = .270212 if constituencynumber == 12005
replace competition = .357988 if constituencynumber == 12006
replace competition = .3380255 if constituencynumber == 12007
replace competition = .29711 if constituencynumber == 12008
replace competition = .3833255 if constituencynumber == 12009
replace competition = .3297835 if constituencynumber == 12010
replace competition = .3384015 if constituencynumber == 12011
replace competition = .2200335 if constituencynumber == 13001
replace competition = .3585955 if constituencynumber == 13002
replace competition = .3779935 if constituencynumber == 13003
replace competition = .269632 if constituencynumber == 13004
replace competition = .358264 if constituencynumber == 13005
replace competition = .29902 if constituencynumber == 13006
replace competition = .3894455 if constituencynumber == 13007
replace competition = .2515495 if constituencynumber == 13008
replace competition = .3365335 if constituencynumber == 13009
replace competition = .272852 if constituencynumber == 13010
replace competition = .3593135 if constituencynumber == 24001
replace competition = .3766535 if constituencynumber == 24002
replace competition = .37445 if constituencynumber == 24003
replace competition = .4315495 if constituencynumber == 24004
replace competition = .4248315 if constituencynumber == 24005
replace competition = .4749755 if constituencynumber == 24006
replace competition = .397216 if constituencynumber == 24007
replace competition = .4140035 if constituencynumber == 24008
replace competition = .4243455 if constituencynumber == 24009
replace competition = .44421 if constituencynumber == 24010
replace competition = .355294 if constituencynumber == 24011
replace competition = .410686 if constituencynumber == 24012
replace competition = .396682 if constituencynumber == 24013
replace competition = .4009615 if constituencynumber == 24014
replace competition = .453808 if constituencynumber == 24015
replace competition = .430356 if constituencynumber == 24016
replace competition = .4164975 if constituencynumber == 24017
replace competition = .3900295 if constituencynumber == 24018
replace competition = .435274 if constituencynumber == 24019
replace competition = .409816 if constituencynumber == 24020
replace competition = .4200735 if constituencynumber == 24021
replace competition = .37944 if constituencynumber == 24022
replace competition = .4060935 if constituencynumber == 24023
replace competition = .4248035 if constituencynumber == 24024
replace competition = .404972 if constituencynumber == 24025
replace competition = .335696 if constituencynumber == 24026
replace competition = .388838 if constituencynumber == 24027
replace competition = .35123 if constituencynumber == 24028
replace competition = .4382055 if constituencynumber == 24029
replace competition = .3461435 if constituencynumber == 24030
replace competition = .3794675 if constituencynumber == 24031
replace competition = .3838055 if constituencynumber == 24032
replace competition = .366822 if constituencynumber == 24033
replace competition = .4097895 if constituencynumber == 24034
replace competition = .392524 if constituencynumber == 24035
replace competition = .3859955 if constituencynumber == 24036
replace competition = .3868295 if constituencynumber == 24037
replace competition = .354948 if constituencynumber == 24038
replace competition = .378228 if constituencynumber == 24039
replace competition = .4483015 if constituencynumber == 24040
replace competition = .401306 if constituencynumber == 24041
replace competition = .436038 if constituencynumber == 24042
replace competition = .348464 if constituencynumber == 24043
replace competition = .408886 if constituencynumber == 24044
replace competition = .4340655 if constituencynumber == 24045
replace competition = .3845675 if constituencynumber == 24046
replace competition = .3929735 if constituencynumber == 24047
replace competition = .353088 if constituencynumber == 24048
replace competition = .3861735 if constituencynumber == 24049
replace competition = .3972995 if constituencynumber == 24050
replace competition = .38205 if constituencynumber == 24051
replace competition = .250656 if constituencynumber == 24052
replace competition = .4003175 if constituencynumber == 24053
replace competition = .347096 if constituencynumber == 24054
replace competition = .4062075 if constituencynumber == 24055
replace competition = .3959235 if constituencynumber == 24056
replace competition = .412792 if constituencynumber == 24057
replace competition = .4328415 if constituencynumber == 24058
replace competition = .4060755 if constituencynumber == 24059
replace competition = .404776 if constituencynumber == 24060
replace competition = .4181295 if constituencynumber == 24061
replace competition = .3651295 if constituencynumber == 24062
replace competition = .3529755 if constituencynumber == 24063
replace competition = .4294415 if constituencynumber == 24064
replace competition = .42819 if constituencynumber == 24065
replace competition = .3921035 if constituencynumber == 24066
replace competition = .3710795 if constituencynumber == 24067
replace competition = .3977915 if constituencynumber == 24068
replace competition = .3975155 if constituencynumber == 24069
replace competition = .4529415 if constituencynumber == 24070
replace competition = .350646 if constituencynumber == 24071
replace competition = .4309695 if constituencynumber == 24072
replace competition = .3817 if constituencynumber == 24073
replace competition = .4414615 if constituencynumber == 24074
replace competition = .378744 if constituencynumber == 24075
replace competition = .378822 if constituencynumber == 24076
replace competition = .434202 if constituencynumber == 24077
replace competition = .453156 if constituencynumber == 24078
replace competition = .2748735 if constituencynumber == 35001
replace competition = .28145 if constituencynumber == 35002
replace competition = .1217855 if constituencynumber == 35003
replace competition = .2717955 if constituencynumber == 35004
replace competition = .2106015 if constituencynumber == 35005
replace competition = .294932 if constituencynumber == 35006
replace competition = .33677 if constituencynumber == 35007
replace competition = .3027455 if constituencynumber == 35008
replace competition = .362036 if constituencynumber == 35009
replace competition = .308162 if constituencynumber == 35010
replace competition = .2810135 if constituencynumber == 35011
replace competition = .324252 if constituencynumber == 35012
replace competition = .323896 if constituencynumber == 35013
replace competition = .2404715 if constituencynumber == 35014
replace competition = .1779235 if constituencynumber == 35015
replace competition = .25109 if constituencynumber == 35016
replace competition = .2585495 if constituencynumber == 35017
replace competition = .2048355 if constituencynumber == 35018
replace competition = .33059 if constituencynumber == 35019
replace competition = .242566 if constituencynumber == 35020
replace competition = .239266 if constituencynumber == 35021
replace competition = .24333 if constituencynumber == 35022
replace competition = .2823255 if constituencynumber == 35023
replace competition = .1691535 if constituencynumber == 35024
replace competition = .339704 if constituencynumber == 35025
replace competition = .2698915 if constituencynumber == 35026
replace competition = .2462835 if constituencynumber == 35027
replace competition = .3119935 if constituencynumber == 35028
replace competition = .358438 if constituencynumber == 35029
replace competition = .238758 if constituencynumber == 35030
replace competition = .2590255 if constituencynumber == 35031
replace competition = .403208 if constituencynumber == 35032
replace competition = .2860255 if constituencynumber == 35033
replace competition = .32783 if constituencynumber == 35034
replace competition = .32781 if constituencynumber == 35035
replace competition = .2962674 if constituencynumber == 35036
replace competition = .294302 if constituencynumber == 35037
replace competition = .3309455 if constituencynumber == 35038
replace competition = .1924255 if constituencynumber == 35039
replace competition = .225478 if constituencynumber == 35040
replace competition = .2221455 if constituencynumber == 35041
replace competition = .260018 if constituencynumber == 35042
replace competition = .141588 if constituencynumber == 35043
replace competition = .3920775 if constituencynumber == 35044
replace competition = .345998 if constituencynumber == 35045
replace competition = .1829515 if constituencynumber == 35046
replace competition = .283124 if constituencynumber == 35047
replace competition = .346518 if constituencynumber == 35048
replace competition = .3107615 if constituencynumber == 35049
replace competition = .212166 if constituencynumber == 35050
replace competition = .304038 if constituencynumber == 35051
replace competition = .334922 if constituencynumber == 35052
replace competition = .2931495 if constituencynumber == 35053
replace competition = .16342 if constituencynumber == 35054
replace competition = .299778 if constituencynumber == 35055
replace competition = .1534915 if constituencynumber == 35056
replace competition = .218298 if constituencynumber == 35057
replace competition = .2914295 if constituencynumber == 35058
replace competition = .268436 if constituencynumber == 35059
replace competition = .2234755 if constituencynumber == 35060
replace competition = .1998895 if constituencynumber == 35061
replace competition = .3487575 if constituencynumber == 35062
replace competition = .212522 if constituencynumber == 35063
replace competition = .2679895 if constituencynumber == 35064
replace competition = .18177 if constituencynumber == 35065
replace competition = .28704 if constituencynumber == 35066
replace competition = .28745 if constituencynumber == 35067
replace competition = .3357675 if constituencynumber == 35068
replace competition = .252946 if constituencynumber == 35069
replace competition = .342924 if constituencynumber == 35070
replace competition = .2297175 if constituencynumber == 35071
replace competition = .1689395 if constituencynumber == 35072
replace competition = .162322 if constituencynumber == 35073
replace competition = .2936835 if constituencynumber == 35074
replace competition = .252696 if constituencynumber == 35075
replace competition = .30687 if constituencynumber == 35076
replace competition = .3681141 if constituencynumber == 35077
replace competition = .393524 if constituencynumber == 35078
replace competition = .3348875 if constituencynumber == 35079
replace competition = .3362375 if constituencynumber == 35080
replace competition = .228796 if constituencynumber == 35081
replace competition = .254602 if constituencynumber == 35082
replace competition = .2665095 if constituencynumber == 35083
replace competition = .2843995 if constituencynumber == 35084
replace competition = .2403455 if constituencynumber == 35085
replace competition = .3453475 if constituencynumber == 35086
replace competition = .158996 if constituencynumber == 35087
replace competition = .15493 if constituencynumber == 35088
replace competition = .255876 if constituencynumber == 35089
replace competition = .3576375 if constituencynumber == 35090
replace competition = .3034675 if constituencynumber == 35091
replace competition = .3217355 if constituencynumber == 35092
replace competition = .2390375 if constituencynumber == 35093
replace competition = .324584 if constituencynumber == 35094
replace competition = .3439575 if constituencynumber == 35095
replace competition = .35202 if constituencynumber == 35096
replace competition = .335624 if constituencynumber == 35097
replace competition = .37395 if constituencynumber == 35098
replace competition = .250376 if constituencynumber == 35099
replace competition = .2401715 if constituencynumber == 35100
replace competition = .354214 if constituencynumber == 35101
replace competition = .233196 if constituencynumber == 35102
replace competition = .359348 if constituencynumber == 35103
replace competition = .274804 if constituencynumber == 35104
replace competition = .3504075 if constituencynumber == 35105
replace competition = .428878 if constituencynumber == 35106
replace competition = .283788 if constituencynumber == 35107
replace competition = .3568395 if constituencynumber == 35108
replace competition = .2389215 if constituencynumber == 35109
replace competition = .357946 if constituencynumber == 35110
replace competition = .145386 if constituencynumber == 35111
replace competition = .320112 if constituencynumber == 35112
replace competition = .269186 if constituencynumber == 35113
replace competition = .1873795 if constituencynumber == 35114
replace competition = .250934 if constituencynumber == 35115
replace competition = .339588 if constituencynumber == 35116
replace competition = .3678275 if constituencynumber == 35117
replace competition = .1465735 if constituencynumber == 35118
replace competition = .24878 if constituencynumber == 35119
replace competition = .34532 if constituencynumber == 35120
replace competition = .3503655 if constituencynumber == 35121
replace competition = .259912 if constituencynumber == 46001
replace competition = .222468 if constituencynumber == 46002
replace competition = .189722 if constituencynumber == 46003
replace competition = .38657 if constituencynumber == 46004
replace competition = .2530975 if constituencynumber == 46005
replace competition = .2284655 if constituencynumber == 46006
replace competition = .359686 if constituencynumber == 46007
replace competition = .274466 if constituencynumber == 46008
replace competition = .3321275 if constituencynumber == 46009
replace competition = .3362055 if constituencynumber == 46010
replace competition = .3623435 if constituencynumber == 46011
replace competition = .35147 if constituencynumber == 46012
replace competition = .261452 if constituencynumber == 46013
replace competition = .3337175 if constituencynumber == 46014
replace competition = .393794 if constituencynumber == 47001
replace competition = .3513675 if constituencynumber == 47002
replace competition = .2478035 if constituencynumber == 47003
replace competition = .364822 if constituencynumber == 47004
replace competition = .3750595 if constituencynumber == 47005
replace competition = .3442355 if constituencynumber == 47006
replace competition = .2539235 if constituencynumber == 47007
replace competition = .3275535 if constituencynumber == 47008
replace competition = .326996 if constituencynumber == 47009
replace competition = .312054 if constituencynumber == 47010
replace competition = .303084 if constituencynumber == 47011
replace competition = .2979755 if constituencynumber == 47012
replace competition = .345612 if constituencynumber == 47013
replace competition = .380406 if constituencynumber == 47014
replace competition = .3355575 if constituencynumber == 48001
replace competition = .2647175 if constituencynumber == 48002
replace competition = .2976995 if constituencynumber == 48003
replace competition = .123238 if constituencynumber == 48004
replace competition = .161124 if constituencynumber == 48005
replace competition = .292574 if constituencynumber == 48006
replace competition = .332774 if constituencynumber == 48007
replace competition = .3397835 if constituencynumber == 48008
replace competition = .3475495 if constituencynumber == 48009
replace competition = .2897275 if constituencynumber == 48010
replace competition = .32951 if constituencynumber == 48011
replace competition = .306218 if constituencynumber == 48012
replace competition = .2378095 if constituencynumber == 48013
replace competition = .273288 if constituencynumber == 48014
replace competition = .30241 if constituencynumber == 48015
replace competition = .35554 if constituencynumber == 48016
replace competition = .2164716 if constituencynumber == 48017
replace competition = .3391395 if constituencynumber == 48018
replace competition = .3336056 if constituencynumber == 48019
replace competition = .289428 if constituencynumber == 48020
replace competition = .3529515 if constituencynumber == 48021
replace competition = .3149835 if constituencynumber == 48022
replace competition = .330116 if constituencynumber == 48023
replace competition = .333134 if constituencynumber == 48024
replace competition = .3336195 if constituencynumber == 48025
replace competition = .3943935 if constituencynumber == 48026
replace competition = .3525075 if constituencynumber == 48027
replace competition = .354098 if constituencynumber == 48028
replace competition = .3235355 if constituencynumber == 48029
replace competition = .3437015 if constituencynumber == 48030
replace competition = .4313875 if constituencynumber == 48031
replace competition = .3779395 if constituencynumber == 48032
replace competition = .350228 if constituencynumber == 48033
replace competition = .3399975 if constituencynumber == 48034
replace competition = .3247735 if constituencynumber == 59001
replace competition = .3338775 if constituencynumber == 59002
replace competition = .276394 if constituencynumber == 59003
replace competition = .3227135 if constituencynumber == 59004
replace competition = .261404 if constituencynumber == 59005
replace competition = .3165975 if constituencynumber == 59006
replace competition = .2989075 if constituencynumber == 59007
replace competition = .3067115 if constituencynumber == 59008
replace competition = .3821175 if constituencynumber == 59009
replace competition = .4197295 if constituencynumber == 59010
replace competition = .3155975 if constituencynumber == 59011
replace competition = .339212 if constituencynumber == 59012
replace competition = .2923355 if constituencynumber == 59013
replace competition = .212382 if constituencynumber == 59014
replace competition = .274644 if constituencynumber == 59015
replace competition = .281754 if constituencynumber == 59016
replace competition = .3035795 if constituencynumber == 59017
replace competition = .4144175 if constituencynumber == 59018
replace competition = .3739995 if constituencynumber == 59019
replace competition = .3343 if constituencynumber == 59020
replace competition = .36692 if constituencynumber == 59021
replace competition = .2970735 if constituencynumber == 59022
replace competition = .2968675 if constituencynumber == 59023
replace competition = .398048 if constituencynumber == 59024
replace competition = .200684 if constituencynumber == 59025
replace competition = .3945 if constituencynumber == 59026
replace competition = .4221775 if constituencynumber == 59027
replace competition = .3897295 if constituencynumber == 59028
replace competition = .3225575 if constituencynumber == 59029
replace competition = .2037355 if constituencynumber == 59030
replace competition = .25128 if constituencynumber == 59031
replace competition = .351334 if constituencynumber == 59032
replace competition = .3582915 if constituencynumber == 59033
replace competition = .4102455 if constituencynumber == 59034
replace competition = .3874075 if constituencynumber == 59035
replace competition = .348664 if constituencynumber == 59036
replace competition = .378414 if constituencynumber == 59037
replace competition = .3711255 if constituencynumber == 59038
replace competition = .3629495 if constituencynumber == 59039
replace competition = .3059415 if constituencynumber == 59040
replace competition = .34728 if constituencynumber == 59041
replace competition = .383914 if constituencynumber == 59042
replace competition = .37206 if constituencynumber == 60001
replace competition = .334562 if constituencynumber == 61001
replace competition = .3455175 if constituencynumber == 62001


*******************************
** INCUMBENT PARTY REELECTED **
*******************************

gen reelected = .

replace reelected = 1 if constituencynumber == 10001
replace reelected = 1 if constituencynumber == 10002
replace reelected = 1 if constituencynumber == 10003
replace reelected = 1 if constituencynumber == 10004
replace reelected = 1 if constituencynumber == 10005
replace reelected = 0 if constituencynumber == 10006
replace reelected = 1 if constituencynumber == 10007
replace reelected = 1 if constituencynumber == 11001
replace reelected = 1 if constituencynumber == 11002
replace reelected = 1 if constituencynumber == 11003
replace reelected = 1 if constituencynumber == 11004
replace reelected = 1 if constituencynumber == 12001
replace reelected = 1 if constituencynumber == 12002
replace reelected = 1 if constituencynumber == 12003
replace reelected = 1 if constituencynumber == 12004
replace reelected = 1 if constituencynumber == 12005
replace reelected = 1 if constituencynumber == 12006
replace reelected = 1 if constituencynumber == 12007
replace reelected = 1 if constituencynumber == 12008
replace reelected = 1 if constituencynumber == 12009
replace reelected = 1 if constituencynumber == 12010
replace reelected = 0 if constituencynumber == 12011
replace reelected = 1 if constituencynumber == 13001
replace reelected = 1 if constituencynumber == 13002
replace reelected = 0 if constituencynumber == 13003
replace reelected = 0 if constituencynumber == 13004
replace reelected = 1 if constituencynumber == 13005
replace reelected = 1 if constituencynumber == 13006
replace reelected = 1 if constituencynumber == 13007
replace reelected = 0 if constituencynumber == 13008
replace reelected = 1 if constituencynumber == 13009
replace reelected = 0 if constituencynumber == 13010
replace reelected = 0 if constituencynumber == 24001
replace reelected = 0 if constituencynumber == 24002
replace reelected = 1 if constituencynumber == 24003
replace reelected = 1 if constituencynumber == 24004
replace reelected = 1 if constituencynumber == 24005
replace reelected = 0 if constituencynumber == 24006
replace reelected = 1 if constituencynumber == 24007
replace reelected = 0 if constituencynumber == 24008
replace reelected = 1 if constituencynumber == 24009
replace reelected = 1 if constituencynumber == 24010
replace reelected = 0 if constituencynumber == 24011
replace reelected = 0 if constituencynumber == 24012
replace reelected = 0 if constituencynumber == 24013
replace reelected = 1 if constituencynumber == 24014
replace reelected = 1 if constituencynumber == 24015
replace reelected = 1 if constituencynumber == 24016
replace reelected = 1 if constituencynumber == 24017
replace reelected = 0 if constituencynumber == 24018
replace reelected = 1 if constituencynumber == 24019
replace reelected = 0 if constituencynumber == 24020
replace reelected = 1 if constituencynumber == 24021
replace reelected = 0 if constituencynumber == 24022
replace reelected = 1 if constituencynumber == 24023
replace reelected = 1 if constituencynumber == 24024
replace reelected = 0 if constituencynumber == 24025
replace reelected = 1 if constituencynumber == 24026
replace reelected = 1 if constituencynumber == 24027
replace reelected = 0 if constituencynumber == 24028
replace reelected = 1 if constituencynumber == 24029
replace reelected = 1 if constituencynumber == 24030
replace reelected = 1 if constituencynumber == 24031
replace reelected = 0 if constituencynumber == 24032
replace reelected = 1 if constituencynumber == 24033
replace reelected = 0 if constituencynumber == 24034
replace reelected = 0 if constituencynumber == 24035
replace reelected = 1 if constituencynumber == 24036
replace reelected = 1 if constituencynumber == 24037
replace reelected = 0 if constituencynumber == 24038
replace reelected = 0 if constituencynumber == 24039
replace reelected = 1 if constituencynumber == 24040
replace reelected = 1 if constituencynumber == 24041
replace reelected = 1 if constituencynumber == 24042
replace reelected = 0 if constituencynumber == 24043
replace reelected = 1 if constituencynumber == 24044
replace reelected = 1 if constituencynumber == 24045
replace reelected = 1 if constituencynumber == 24046
replace reelected = 1 if constituencynumber == 24047
replace reelected = 1 if constituencynumber == 24048
replace reelected = 0 if constituencynumber == 24049
replace reelected = 1 if constituencynumber == 24050
replace reelected = 1 if constituencynumber == 24051
replace reelected = 1 if constituencynumber == 24052
replace reelected = 1 if constituencynumber == 24053
replace reelected = 0 if constituencynumber == 24054
replace reelected = 1 if constituencynumber == 24055
replace reelected = 1 if constituencynumber == 24056
replace reelected = 1 if constituencynumber == 24057
replace reelected = 1 if constituencynumber == 24058
replace reelected = 1 if constituencynumber == 24059
replace reelected = 1 if constituencynumber == 24060
replace reelected = 1 if constituencynumber == 24061
replace reelected = 0 if constituencynumber == 24062
replace reelected = 1 if constituencynumber == 24063
replace reelected = 1 if constituencynumber == 24064
replace reelected = 1 if constituencynumber == 24065
replace reelected = 0 if constituencynumber == 24066
replace reelected = 0 if constituencynumber == 24067
replace reelected = 1 if constituencynumber == 24068
replace reelected = 1 if constituencynumber == 24069
replace reelected = 1 if constituencynumber == 24070
replace reelected = 0 if constituencynumber == 24071
replace reelected = 0 if constituencynumber == 24072
replace reelected = 0 if constituencynumber == 24073
replace reelected = 1 if constituencynumber == 24074
replace reelected = 1 if constituencynumber == 24075
replace reelected = 0 if constituencynumber == 24076
replace reelected = 1 if constituencynumber == 24077
replace reelected = 1 if constituencynumber == 24078
replace reelected = 1 if constituencynumber == 35001
replace reelected = 1 if constituencynumber == 35002
replace reelected = 0 if constituencynumber == 35003
replace reelected = 1 if constituencynumber == 35004
replace reelected = 1 if constituencynumber == 35005
replace reelected = 1 if constituencynumber == 35006
replace reelected = 1 if constituencynumber == 35007
replace reelected = 1 if constituencynumber == 35008
replace reelected = 1 if constituencynumber == 35009
replace reelected = 1 if constituencynumber == 35010
replace reelected = 1 if constituencynumber == 35011
replace reelected = 1 if constituencynumber == 35012
replace reelected = 1 if constituencynumber == 35013
replace reelected = 1 if constituencynumber == 35014
replace reelected = 1 if constituencynumber == 35015
replace reelected = 1 if constituencynumber == 35016
replace reelected = 1 if constituencynumber == 35017
replace reelected = 1 if constituencynumber == 35018
replace reelected = 1 if constituencynumber == 35019
replace reelected = 1 if constituencynumber == 35020
replace reelected = 1 if constituencynumber == 35021
replace reelected = 1 if constituencynumber == 35022
replace reelected = 1 if constituencynumber == 35023
replace reelected = 1 if constituencynumber == 35024
replace reelected = 1 if constituencynumber == 35025
replace reelected = 0 if constituencynumber == 35026
replace reelected = 1 if constituencynumber == 35027
replace reelected = 1 if constituencynumber == 35028
replace reelected = 1 if constituencynumber == 35029
replace reelected = 1 if constituencynumber == 35030
replace reelected = 1 if constituencynumber == 35031
replace reelected = 1 if constituencynumber == 35032
replace reelected = 1 if constituencynumber == 35033
replace reelected = 1 if constituencynumber == 35034
replace reelected = 1 if constituencynumber == 35035
replace reelected = 1 if constituencynumber == 35036
replace reelected = 1 if constituencynumber == 35037
replace reelected = 1 if constituencynumber == 35038
replace reelected = 0 if constituencynumber == 35039
replace reelected = 1 if constituencynumber == 35040
replace reelected = 1 if constituencynumber == 35041
replace reelected = 0 if constituencynumber == 35042
replace reelected = 1 if constituencynumber == 35043
replace reelected = 1 if constituencynumber == 35044
replace reelected = 1 if constituencynumber == 35045
replace reelected = 0 if constituencynumber == 35046
replace reelected = 1 if constituencynumber == 35047
replace reelected = 1 if constituencynumber == 35048
replace reelected = 1 if constituencynumber == 35049
replace reelected = 1 if constituencynumber == 35050
replace reelected = 1 if constituencynumber == 35051
replace reelected = 1 if constituencynumber == 35052
replace reelected = 1 if constituencynumber == 35053
replace reelected = 1 if constituencynumber == 35054
replace reelected = 1 if constituencynumber == 35055
replace reelected = 1 if constituencynumber == 35056
replace reelected = 0 if constituencynumber == 35057
replace reelected = 1 if constituencynumber == 35058
replace reelected = 1 if constituencynumber == 35059
replace reelected = 1 if constituencynumber == 35060
replace reelected = 1 if constituencynumber == 35061
replace reelected = 1 if constituencynumber == 35062
replace reelected = 1 if constituencynumber == 35063
replace reelected = 1 if constituencynumber == 35064
replace reelected = 1 if constituencynumber == 35065
replace reelected = 1 if constituencynumber == 35066
replace reelected = 1 if constituencynumber == 35067
replace reelected = 1 if constituencynumber == 35068
replace reelected = 1 if constituencynumber == 35069
replace reelected = 1 if constituencynumber == 35070
replace reelected = 0 if constituencynumber == 35071
replace reelected = 1 if constituencynumber == 35072
replace reelected = 1 if constituencynumber == 35073
replace reelected = 1 if constituencynumber == 35074
replace reelected = 1 if constituencynumber == 35075
replace reelected = 1 if constituencynumber == 35076
replace reelected = 1 if constituencynumber == 35077
replace reelected = 1 if constituencynumber == 35078
replace reelected = 1 if constituencynumber == 35079
replace reelected = 1 if constituencynumber == 35080
replace reelected = 1 if constituencynumber == 35081
replace reelected = 1 if constituencynumber == 35082
replace reelected = 1 if constituencynumber == 35083
replace reelected = 1 if constituencynumber == 35084
replace reelected = 1 if constituencynumber == 35085
replace reelected = 1 if constituencynumber == 35086
replace reelected = 1 if constituencynumber == 35087
replace reelected = 1 if constituencynumber == 35088
replace reelected = 1 if constituencynumber == 35089
replace reelected = 1 if constituencynumber == 35090
replace reelected = 1 if constituencynumber == 35091
replace reelected = 1 if constituencynumber == 35092
replace reelected = 1 if constituencynumber == 35093
replace reelected = 1 if constituencynumber == 35094
replace reelected = 1 if constituencynumber == 35095
replace reelected = 1 if constituencynumber == 35096
replace reelected = 1 if constituencynumber == 35097
replace reelected = 1 if constituencynumber == 35098
replace reelected = 1 if constituencynumber == 35099
replace reelected = 1 if constituencynumber == 35100
replace reelected = 1 if constituencynumber == 35101
replace reelected = 1 if constituencynumber == 35102
replace reelected = 1 if constituencynumber == 35103
replace reelected = 1 if constituencynumber == 35104
replace reelected = 1 if constituencynumber == 35105
replace reelected = 1 if constituencynumber == 35106
replace reelected = 1 if constituencynumber == 35107
replace reelected = 1 if constituencynumber == 35108
replace reelected = 1 if constituencynumber == 35109
replace reelected = 1 if constituencynumber == 35110
replace reelected = 1 if constituencynumber == 35111
replace reelected = 1 if constituencynumber == 35112
replace reelected = 1 if constituencynumber == 35113
replace reelected = 1 if constituencynumber == 35114
replace reelected = 1 if constituencynumber == 35115
replace reelected = 0 if constituencynumber == 35116
replace reelected = 1 if constituencynumber == 35117
replace reelected = 1 if constituencynumber == 35118
replace reelected = 1 if constituencynumber == 35119
replace reelected = 1 if constituencynumber == 35120
replace reelected = 1 if constituencynumber == 35121
replace reelected = 1 if constituencynumber == 46001
replace reelected = 0 if constituencynumber == 46002
replace reelected = 1 if constituencynumber == 46003
replace reelected = 1 if constituencynumber == 46004
replace reelected = 1 if constituencynumber == 46005
replace reelected = 0 if constituencynumber == 46006
replace reelected = 1 if constituencynumber == 46007
replace reelected = 1 if constituencynumber == 46008
replace reelected = 1 if constituencynumber == 46009
replace reelected = 1 if constituencynumber == 46010
replace reelected = 0 if constituencynumber == 46011
replace reelected = 1 if constituencynumber == 46012
replace reelected = 1 if constituencynumber == 46013
replace reelected = 1 if constituencynumber == 46014
replace reelected = 1 if constituencynumber == 47001
replace reelected = 1 if constituencynumber == 47002
replace reelected = 0 if constituencynumber == 47003
replace reelected = 1 if constituencynumber == 47004
replace reelected = 1 if constituencynumber == 47005
replace reelected = 1 if constituencynumber == 47006
replace reelected = 0 if constituencynumber == 47007
replace reelected = 1 if constituencynumber == 47008
replace reelected = 0 if constituencynumber == 47009
replace reelected = 1 if constituencynumber == 47010
replace reelected = 1 if constituencynumber == 47011
replace reelected = 0 if constituencynumber == 47012
replace reelected = 1 if constituencynumber == 47013
replace reelected = 1 if constituencynumber == 47014
replace reelected = 1 if constituencynumber == 48001
replace reelected = 1 if constituencynumber == 48002
replace reelected = 1 if constituencynumber == 48003
replace reelected = 0 if constituencynumber == 48004
replace reelected = 1 if constituencynumber == 48005
replace reelected = 1 if constituencynumber == 48006
replace reelected = 1 if constituencynumber == 48007
replace reelected = 1 if constituencynumber == 48008
replace reelected = 1 if constituencynumber == 48009
replace reelected = 1 if constituencynumber == 48010
replace reelected = 1 if constituencynumber == 48011
replace reelected = 1 if constituencynumber == 48012
replace reelected = 0 if constituencynumber == 48013
replace reelected = 0 if constituencynumber == 48014
replace reelected = 1 if constituencynumber == 48015
replace reelected = 1 if constituencynumber == 48016
replace reelected = 0 if constituencynumber == 48017
replace reelected = 1 if constituencynumber == 48018
replace reelected = 1 if constituencynumber == 48019
replace reelected = 1 if constituencynumber == 48020
replace reelected = 1 if constituencynumber == 48021
replace reelected = 1 if constituencynumber == 48022
replace reelected = 1 if constituencynumber == 48023
replace reelected = 1 if constituencynumber == 48024
replace reelected = 1 if constituencynumber == 48025
replace reelected = 1 if constituencynumber == 48026
replace reelected = 1 if constituencynumber == 48027
replace reelected = 1 if constituencynumber == 48028
replace reelected = 1 if constituencynumber == 48029
replace reelected = 1 if constituencynumber == 48030
replace reelected = 1 if constituencynumber == 48031
replace reelected = 1 if constituencynumber == 48032
replace reelected = 1 if constituencynumber == 48033
replace reelected = 1 if constituencynumber == 48034
replace reelected = 1 if constituencynumber == 59001
replace reelected = 1 if constituencynumber == 59002
replace reelected = 1 if constituencynumber == 59003
replace reelected = 1 if constituencynumber == 59004
replace reelected = 1 if constituencynumber == 59005
replace reelected = 1 if constituencynumber == 59006
replace reelected = 0 if constituencynumber == 59007
replace reelected = 1 if constituencynumber == 59008
replace reelected = 1 if constituencynumber == 59009
replace reelected = 1 if constituencynumber == 59010
replace reelected = 1 if constituencynumber == 59011
replace reelected = 1 if constituencynumber == 59012
replace reelected = 1 if constituencynumber == 59013
replace reelected = 0 if constituencynumber == 59014
replace reelected = 0 if constituencynumber == 59015
replace reelected = 1 if constituencynumber == 59016
replace reelected = 0 if constituencynumber == 59017
replace reelected = 0 if constituencynumber == 59018
replace reelected = 1 if constituencynumber == 59019
replace reelected = 1 if constituencynumber == 59020
replace reelected = 1 if constituencynumber == 59021
replace reelected = 0 if constituencynumber == 59022
replace reelected = 0 if constituencynumber == 59023
replace reelected = 1 if constituencynumber == 59024
replace reelected = 1 if constituencynumber == 59025
replace reelected = 1 if constituencynumber == 59026
replace reelected = 0 if constituencynumber == 59027
replace reelected = 1 if constituencynumber == 59028
replace reelected = 1 if constituencynumber == 59029
replace reelected = 1 if constituencynumber == 59030
replace reelected = 0 if constituencynumber == 59031
replace reelected = 1 if constituencynumber == 59032
replace reelected = 1 if constituencynumber == 59033
replace reelected = 1 if constituencynumber == 59034
replace reelected = 1 if constituencynumber == 59035
replace reelected = 0 if constituencynumber == 59036
replace reelected = 1 if constituencynumber == 59037
replace reelected = 1 if constituencynumber == 59038
replace reelected = 1 if constituencynumber == 59039
replace reelected = 1 if constituencynumber == 59040
replace reelected = 1 if constituencynumber == 59041
replace reelected = 1 if constituencynumber == 59042
replace reelected = 1 if constituencynumber == 60001
replace reelected = 1 if constituencynumber == 61001
replace reelected = 0 if constituencynumber == 62001


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen sdate = substr(survey_end_CES,1,10)
replace sdate = subinstr(sdate, "-", "",.)
destring sdate, generate(sdate1)

gen surveydate=date(string(sdate1,"%8.0f"),"YMD")

gen edate = 20191021

gen electiondate=date(string(edate,"%8.0f"),"YMD") + 1

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) 

replace time = . if time < 0

* Province

gen province = q4

recode province 10=1 9=2 8=3 7=4 6=5 5=6 4=7 3=8 2=9 1=10

label define province 1 "British Columbia" 2 "Alberta" 3 "Saskatchewan" 4 "Manitoba" 5 "Ontario" 6 "Quebec" 7 "New Brunswick" 8 "Nova Scotia" 9 "Prince Edward Island" 10 "Newfoundland and Labrador" 11 "Northwest Territories" 12 "Yukon" 13 "Nunavut"
label values province province

* Language

gen language = language_CES

recode language 1=0 2=1

label define lang 0 "English" 1 "French"
label values language lang

* Gender

gen male = q3

recode male 2=0 3=.

label define gender 0 "Female" 1 "Male"
label values male gender

* Age // Already coded

* Age 55 and over

gen age55 = 1 if age >= 55
replace age55 = 0 if age < 55 & age!=.

label define age55 0 "Less than 55" 1 "55 and over"
label values age55 age55

* Education

gen education = q61

recode education 1=901 2=902 3=903 4=904 5=905 6=906 7=907 8=908 9=909 10=910 11=911 -9=. -8=.

label define education 901 "No schooling" 902 "Some elementary school" 903 "Completed elementary school" 904 "Some secondary/high school" 905 "Completed secondary/high school" 906 "Some technical, community college, CEGEP, College Classique" 907 "Completed technical, community college, CEGEP, College Classique" 908 "Some university" 909 "Bachelor's degree" 910 "Master's degree" 911 "Professional degree or doctorate" 
label values education education

* University degree

gen univ = 1 if education >= 909
replace univ = 0 if education < 909 & education!=.

label define univ 0 "No university degree" 1 "University degree"
label values univ univ

* Postgraduate degree

gen postgrad = 1 if education == 910
replace postgrad = 0 if education < 910 & education!=.

label define postgrad 0 "No postgraduate degree" 1 "Postgraduate degree"
label values postgrad postgrad

* Postsecondary degree

gen postsec = 1 if education >= 907
replace postsec = 0 if education < 907 & education!=.

label define postsec 0 "No postsecondary" 1 "Postsecondary"
label values postsec postsec

* Immigrant

gen immigrant = q64

recode immigrant -9=. -8=. 1=0 2=0 3/13=1

label define immigrant 0 "Born in Canada" 1 "Immigrant"
label values immigrant immigrant

* Household income

gen income_n = q69

* Household income (categories)

gen income = q70r // Already combined

recode income 1=881 2=882 3=883 4=884 5=885 6=886 7=887 8=888 -9=. -8=.

label define income 881 "No income" 882 "$1-$30,000" 883 "$30,001-$60,000" 884 "$60,001-$90,000" 885 "$90,001-$110,000" 886 "$110,001-$150,000" 887 "$150,001-$200,000" 888 "More than $200,000"
label values income income

* Household income (quintile)

xtile income5 = income, nq(5)

* Highest income categories

gen highinc = 1 if income5 == 5
replace highinc = 0 if income5 < 5 & income!=.

label define highinc 0 "Others" 1 "Highest incomes"
label values highinc highinc

* Interest for election

gen interest = q9

recode interest -9=. -8=.

* High political interest

gen highint = 1 if interest > 7
replace highint = 0 if interest < 8

* Vote choice

gen vote_choice = vote

recode vote_choice -8=. 1=2 2=1 7=88 8=0 9=0 10=0 11=. // Recode to match other datasets

label define voteint 0 "None/Will not vote" 1 "CPC" 2 "LPC" 3 "NDP" 4 "BQ" 5 "GPC" 6 "PPC" 88 "Other"
label values vote_choice voteint

* Vote status (district)

gen vote_district = 1 if vote_choice == district_outcome
replace vote_district = 0 if vote_choice!=district_outcome & vote_choice!=. & vote_choice!=0 

label define winner 0 "Voted for loser" 1 "Voted for winner"
label values vote_district winner

* Vote status (national)

gen vote_whole = 1 if vote_choice == 2
replace vote_whole = 0 if vote_choice!=2 & vote_choice!=. 

label values vote_whole winner

* Party identification

gen pid = q52

recode pid -9=9 -8=9 8=0 1=2 2=1 7=88

label define pid 0 "No PID" 1 "Conservative" 2 "Liberal" 3 "NDP" 4 "Bloc" 5 "Green" 6 "People's Party" 88 "Other" 9 "Don't know/Refused"
label values pid pid

* Party identification strength

gen pid_strength = q53

recode pid_strength 1=3 3=1 -9=. -8=.

label define strength 1 "Not very strongly" 2 "Fairly strongly" 3 "Very strongly"
label values pid_strength strength

* Party identification status (district)

gen pidstatus_district = .

replace pidstatus_district = 2 if pid == 0
replace pidstatus_district = 3 if pid == district_outcome & pid!=.
replace pidstatus_district = 1 if pid!=district_outcome & pid!=. & pidstatus_district!=2
replace pidstatus_district = 1 if pid == 2 & district_outcome!=2
replace pidstatus_district = 3 if pid == 2 & district_outcome == 2

replace pidstatus_district = . if pid == 9

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID" 
label values pidstatus_district pidstatus

* Party identification status (national)

gen pidstatus_whole = .

replace pidstatus_whole = 2 if pid == 0
replace pidstatus_whole = 3 if pid == 1
replace pidstatus_whole = 1 if pid!=1 & pid!=. & pidstatus_whole!=2
replace pidstatus_whole = 1 if pid == 2

replace pidstatus_whole = . if pid == 9

label values pidstatus_whole pidstatus

* Party identification scale (district)

gen pidscale_district = .

replace pidscale_district = 1 if pidstatus_district == 1 & pid_strength == 3
replace pidscale_district = 2 if pidstatus_district == 1 & pid_strength == 2
replace pidscale_district = 3 if pidstatus_district == 1 & pid_strength == 1
replace pidscale_district = 4 if pidstatus_district == 2
replace pidscale_district = 5 if pidstatus_district == 3 & pid_strength == 1
replace pidscale_district = 6 if pidstatus_district == 3 & pid_strength == 2
replace pidscale_district = 7 if pidstatus_district == 3 & pid_strength == 3

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID"
label values pidscale_district pidscale

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & pid_strength == 3
replace pidscale_whole = 2 if pidstatus_whole == 1 & pid_strength == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & pid_strength == 1
replace pidscale_whole = 4 if pidstatus_whole == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & pid_strength == 1
replace pidscale_whole = 6 if pidstatus_whole == 3 & pid_strength == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & pid_strength == 3

label values pidscale_whole pidscale

* Relative feeling toward party of choice

gen plc1 = q15
gen plc2 = q16
gen plc3 = q17
gen plc4 = q18
gen plc5 = q19

recode plc* (-9=.) (-8=.) (-6=.)

rowsort plc*, gen(lib1-lib5) descend

gen plc0 = q14
recode plc0 -9=. -8=. -6=.

gen cpc1 = q14
gen cpc2 = q16
gen cpc3 = q17
gen cpc4 = q18
gen cpc5 = q19

recode cpc* (-9=.) (-8=.) (-6=.)

rowsort cpc*, gen(con1-con5) descend

gen cpc0 = q15
recode cpc0 -9=. -8=. -6=.

gen ndp1 = q14
gen ndp2 = q15
gen ndp3 = q17
gen ndp4 = q18
gen ndp5 = q19

recode ndp* (-9=.) (-8=.) (-6=.)

rowsort ndp*, gen(new1-new5) descend

gen ndp0 = q16
recode ndp0 -9=. -8=. -6=.

gen bq1 = q14
gen bq2 = q15
gen bq3 = q16
gen bq4 = q18
gen bq5 = q19

recode bq* (-9=.) (-8=.) (-6=.)

rowsort bq*, gen(bloc1-bloc5) descend

gen bq0 = q17
recode bq0 -9=. -8=. -6=.

gen gpc1 = q14
gen gpc2 = q15
gen gpc3 = q16
gen gpc4 = q17
gen gpc5 = q19

recode gpc* (-9=0) (-8=0) (-6=0)

rowsort gpc*, gen(grn1-grn5) descend

gen gpc0 = q18
recode gpc0 -9=. -8=. -6=.

gen ppc1 = q14
gen ppc2 = q15
gen ppc3 = q16
gen ppc4 = q17
gen ppc5 = q18

recode ppc* (-9=0) (-8=0) (-6=0)

rowsort ppc*, gen(pop1-pop5) descend

gen ppc0 = q19
recode ppc0 -9=. -8=. -6=.

gen first_party = .

replace first_party = plc0 if vote_choice == 2
replace first_party = cpc0 if vote_choice == 1
replace first_party = ndp0 if vote_choice == 3
replace first_party = bq0 if vote_choice == 4
replace first_party = gpc0 if vote_choice == 5
replace first_party = ppc0 if vote_choice == 6

gen relative = .

replace relative = plc0 - plc1 if vote_choice == 2 
replace relative = cpc0 - cpc1 if vote_choice == 1 
replace relative = ndp0 - ndp1 if vote_choice == 3 
replace relative = bq0 - bq1 if vote_choice == 4
replace relative = gpc0 - gpc1 if vote_choice == 5 
replace relative = ppc0 - ppc1 if vote_choice == 6 


*********************************
** DISTRICT-LEVEL EXPECTATIONS **
*********************************

gen forecast_district = q37
recode forecast_district -9=-99 -8=. 1=2 2=1 7=88

gen correct_district_d = 0 if forecast_district!=district_outcome
replace correct_district_d = 1 if forecast_district == district_outcome

egen mean_correct_district_d = mean(correct_district_d)


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

gen forecast_whole = q35
recode forecast_whole -8=. 1=2 2=1 7=88

gen correct_whole_d = 0 if forecast_whole!=2
replace correct_whole_d = 1 if forecast_whole == 2

egen mean_correct_whole_d = mean(correct_whole_d)


*************
** WEIGHTS **
*************

* Sex

gen sex_ca2019_w = male

recode sex_ca2019_w 0=1 1=2

label define sex_ca2019_w 1 "Female" 2 "Male"
label values sex_ca2019_w sex_ca2019_w

* Age

gen age_ca2019_w = age

replace age_ca2019_w = 1 if age_ca2019_w >= 18 & age_ca2019_w <= 19
replace age_ca2019_w = 2 if age_ca2019_w >= 20 & age_ca2019_w <= 24
replace age_ca2019_w = 3 if age_ca2019_w >= 25 & age_ca2019_w <= 29
replace age_ca2019_w = 4 if age_ca2019_w >= 30 & age_ca2019_w <= 34
replace age_ca2019_w = 5 if age_ca2019_w >= 35 & age_ca2019_w <= 39
replace age_ca2019_w = 6 if age_ca2019_w >= 40 & age_ca2019_w <= 44
replace age_ca2019_w = 7 if age_ca2019_w >= 45 & age_ca2019_w <= 49
replace age_ca2019_w = 8 if age_ca2019_w >= 50 & age_ca2019_w <= 54
replace age_ca2019_w = 9 if age_ca2019_w >= 55 & age_ca2019_w <= 59
replace age_ca2019_w = 10 if age_ca2019_w >= 60 & age_ca2019_w <= 64
replace age_ca2019_w = 11 if age_ca2019_w >= 65 & age_ca2019_w <= 69
replace age_ca2019_w = 12 if age_ca2019_w >= 70 & age_ca2019_w <= 74
replace age_ca2019_w = 13 if age_ca2019_w >= 75 & age_ca2019_w <= 79
replace age_ca2019_w = 14 if age_ca2019_w >= 80 & age_ca2019_w <= 84
replace age_ca2019_w = 15 if age_ca2019_w >= 85

label define age_ca2019_w 1 "18-19" 2 "20-24" 3 "25-29" 4 "30-34" 5 "35-39" 6 "40-44" 7 "45-49" 8 "50-54" 9 "55-59" 10 "60-64" 11 "65-69" 12 "70-74" 13 "75-79" 14 "80-84" 15 "85+"
label values age_ca2019_w age_ca2019_w

* Education

gen education_ca2019_w = q61

recode education_ca2019_w -9=. -8=. 2=1 3=1 4=1 5=2 6=2 7=3 8=3 9=4 10=5 11=5

label define education_ca2019_w 1 "Below high school" 2 "High school" 3 "Postsecondary below bachelor" 4 "University undergraduate degree" 5 "University graduate degree"
label values education_ca2019_w education_ca2019_w

* Income

gen income_ca2019_w = q70r

recode income_ca2019_w 2=1 3=2 4=3 5=4 6=5 7=6 8=7 -9=. -8=.

label define income_ca2019_w 1 "Less than $30,000" 2 "$30,001-$60,000" 3 "$60,001-$90,000" 4 "$90,001-$110,000" 5 "$110,001-$150,000" 6 "$150,001-$200,000" 7 "More than $200,000"
label values income_ca2019_w income_ca2019_w

* Province

gen province_ca2019_w = province

replace province_ca2019_w = 10 if province == 1
replace province_ca2019_w = 9 if province == 2
replace province_ca2019_w = 8 if province == 3
replace province_ca2019_w = 7 if province == 4
replace province_ca2019_w = 6 if province == 5
replace province_ca2019_w = 5 if province == 6
replace province_ca2019_w = 4 if province == 7
replace province_ca2019_w = 3 if province == 8
replace province_ca2019_w = 2 if province == 9
replace province_ca2019_w = 1 if province == 10

label define province_ca2019_w 1 "Newfoundland and Labrador" 2 "Prince Edward Island" 3 "Nova Scotia" 4 "New Brunswick" 5 "Quebec" 6 "Ontario" 7 "Manitoba" 8 "Saskatchewan" 9 "Alberta" 10 "British Columbia"
label values province_ca2019_w province_ca2019_w


**********
** SAVE **
**********

save "ca2019_ces_phone.dta", replace

log close